Skip to content

Commit 38670b9

Browse files
committed
Seal the Kind trait
This trait is not intended to be implementable outside of the cxx crate, and by sealing we retain the ability to add methods or associated items into the trait in the future without a breaking change.
1 parent 43232b9 commit 38670b9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/extern_type.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use self::kind::Kind;
1+
use self::kind::{Kind, Opaque, Trivial};
22

33
/// A type for which the layout is determined by its C++ definition.
44
///
@@ -146,6 +146,8 @@ pub unsafe trait ExternType {
146146
/// impls of the `ExternType` trait. Refer to the documentation of `Kind` for an
147147
/// overview of their purpose.
148148
pub mod kind {
149+
use super::private;
150+
149151
/// An opaque type which cannot be passed or held by value within Rust.
150152
///
151153
/// Rust's move semantics are such that every move is equivalent to a
@@ -163,13 +165,19 @@ pub mod kind {
163165
/// indirection.
164166
pub enum Trivial {}
165167

166-
pub trait Kind {}
168+
pub trait Kind: private::Sealed {}
167169
impl Kind for Opaque {}
168170
impl Kind for Trivial {}
169171
}
170172

173+
mod private {
174+
pub trait Sealed {}
175+
impl Sealed for super::Opaque {}
176+
impl Sealed for super::Trivial {}
177+
}
178+
171179
#[doc(hidden)]
172180
pub fn verify_extern_type<T: ExternType<Id = Id>, Id>() {}
173181

174182
#[doc(hidden)]
175-
pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind>() {}
183+
pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind: self::Kind>() {}

0 commit comments

Comments
 (0)