diff --git a/src/lib.rs b/src/lib.rs index e048f871b8..d5025a5504 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -644,16 +644,31 @@ pub type Result = std::result::Result; //////////////////////// +/// 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 Sealed for T{} +} + /// 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