Skip to content

Enhancement 284 Sealed Trait #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,31 @@ pub type Result<T> = std::result::Result<T, Status>;

////////////////////////

/// A common implementation of the sealed supertrait programming pattern
/// (C-SEALED)
///
/// With this, implementations of `Sealed` are guarenteed to only exist in the
/// current crate. This allows modifictation of the underyling traits in ways
/// that would ordinarily be a breaking change for traits that are not sealed.
///
/// See https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed

mod private {
pub trait Sealed {}

impl <T> Sealed for T{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this blanket impl makes sense, because it implements Sealed for all types, even for types defined in other crates. That makes the TensorType: private::Sealed bound useless, because it's implemented for every type already.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, please fix.

}

/// A Rust type that maps to a `DataType`.
///
/// Currently, all implementors must *not* implement Drop (or transitively contain
/// anything that does) and must be bit-for-bit compatible with the corresponding C
/// type. Clients must not implement this trait.
/// type. Clients cannot implement this trait.
///
/// This trait doesn't require `num::Zero` or `num::One` because some tensor
/// types (such as `bool` and `String`) don't implement them and we need to
/// supply custom implementations.
pub trait TensorType: Default + Clone + Display + Debug + 'static {
pub trait TensorType: private::Sealed + Default + Clone + Display + Debug + 'static {
/// Internal only; do not use outside of the tensorflow crate.
///
/// Tensor representation for this type. Normally `TensorDataCRepr` for types
Expand Down