Skip to content
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

Added sealing of functions in traits #19

Closed
wants to merge 10 commits into from
10 changes: 4 additions & 6 deletions demo/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::marker::PhantomData;

use sealed::sealed;

#[sealed]
#[sealed::sealed]
pub trait DroneState {}

pub struct Drone<State>
Expand All @@ -15,15 +13,15 @@ where
}

pub struct Idle;
#[sealed]
#[sealed::sealed]
impl DroneState for Idle {}

pub struct Hovering;
#[sealed]
#[sealed::sealed]
impl DroneState for Hovering {}

pub struct Flying;
#[sealed]
#[sealed::sealed]
impl DroneState for Flying {}

impl Drone<Idle> {
Expand Down
63 changes: 63 additions & 0 deletions examples/partial.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use sealed::sealed;

#[sealed(partial)]
pub trait A {
#[seal(callable)]
fn has_default(
Email(_email): Email,
User {
name: _name,
email: Email(_email2),
age: _age,
}: User,
) {
}

fn not_sealed();
}

pub struct Email(String);

pub struct User {
name: String,
email: Email,
age: u8,
}

pub struct Impl;

#[sealed]
impl A for Impl {
fn not_sealed() {}
}

#[sealed(partial)]
pub trait B {
#[seal(callable)]
fn no_default(_email: Email) {}

fn hello();
}

#[sealed]
impl B for Impl {
#[seal(callable)]
fn no_default(_email: Email) {}

fn hello() {}
}

#[sealed]
pub trait NoPartial {
#[seal(uncallable)]
fn has_default() {}

fn no_default();
}

#[sealed]
impl NoPartial for Impl {
fn no_default() {}
}

fn main() {}
Loading