Skip to content

Commit

Permalink
Make serial::Serial sealed (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
ia0 committed Oct 27, 2023
1 parent 26b7ec4 commit 21e0017
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/prelude/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@

## 0.1.0

<!-- Increment to skip CHANGELOG.md test: 14 -->
<!-- Increment to skip CHANGELOG.md test: 15 -->
6 changes: 6 additions & 0 deletions crates/prelude/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use alloc::boxed::Box;
use core::cell::Cell;
use core::fmt::Debug;

use sealed::sealed;

use crate::scheduling;

/// Serial events to be notified.
Expand All @@ -31,6 +33,10 @@ pub enum Event {
}

/// Provides high-level serial API from low-level API.
///
/// This trait should only be implemented by the prelude and is thus sealed. Its purpose is to
/// provide a unique interface to the different serials.
#[sealed(pub(crate))]
pub trait Serial {
type Error: Clone + Debug;

Expand Down
6 changes: 4 additions & 2 deletions crates/prelude/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

//! Provides API for UART.

use sealed::sealed;
use wasefire_applet_api::uart as api;

use crate::serial::{Event, Serial};
use crate::serial::Event;

/// UART error.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
Expand All @@ -31,7 +32,8 @@ pub fn count() -> usize {
/// Implements the [`Serial`] interface for UART.
pub struct Uart(pub usize);

impl Serial for Uart {
#[sealed]
impl crate::serial::Serial for Uart {
type Error = Error;

fn read(&self, buffer: &mut [u8]) -> Result<usize, Error> {
Expand Down
6 changes: 4 additions & 2 deletions crates/prelude/src/usb/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

//! Provides API for USB serial.

use sealed::sealed;
use wasefire_applet_api::usb::serial as api;

use crate::serial::{Event, Serial};
use crate::serial::Event;
use crate::usb::{convert, Error};

/// Implements the [`Serial`] interface for the USB serial.
pub struct UsbSerial;

impl Serial for UsbSerial {
#[sealed]
impl crate::serial::Serial for UsbSerial {
type Error = Error;

fn read(&self, buffer: &mut [u8]) -> Result<usize, Error> {
Expand Down

0 comments on commit 21e0017

Please sign in to comment.