Skip to content

Remove Trait constraint for Port::new() #188

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

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
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
60 changes: 30 additions & 30 deletions src/instructions/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,37 +100,37 @@ impl PortReadWrite for u32 {}

/// A read only I/O port.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PortReadOnly<T: PortRead> {
pub struct PortReadOnly<T> {
port: u16,
phantom: PhantomData<T>,
}

/// A write only I/O port.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PortWriteOnly<T: PortWrite> {
pub struct PortWriteOnly<T> {
port: u16,
phantom: PhantomData<T>,
}

/// An I/O port.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Port<T: PortReadWrite> {
pub struct Port<T> {
port: u16,
phantom: PhantomData<T>,
}

impl<T: PortRead> PortReadOnly<T> {
const_fn! {
/// Creates a read only I/O port with the given port number.
#[inline]
pub fn new(port: u16) -> PortReadOnly<T> {
PortReadOnly {
port,
phantom: PhantomData,
}
impl<T> PortReadOnly<T> {
/// Creates a read only I/O port with the given port number.
#[inline]
pub const fn new(port: u16) -> PortReadOnly<T> {
PortReadOnly {
port,
phantom: PhantomData,
}
}
}

impl<T: PortRead> PortReadOnly<T> {
/// Reads from the port.
///
/// ## Safety
Expand All @@ -143,18 +143,18 @@ impl<T: PortRead> PortReadOnly<T> {
}
}

impl<T: PortWrite> PortWriteOnly<T> {
const_fn! {
/// Creates a write only I/O port with the given port number.
#[inline]
pub fn new(port: u16) -> PortWriteOnly<T> {
PortWriteOnly {
port,
phantom: PhantomData,
}
impl<T> PortWriteOnly<T> {
/// Creates a write only I/O port with the given port number.
#[inline]
pub const fn new(port: u16) -> PortWriteOnly<T> {
PortWriteOnly {
port,
phantom: PhantomData,
}
}
}

impl<T: PortWrite> PortWriteOnly<T> {
/// Writes to the port.
///
/// ## Safety
Expand All @@ -167,18 +167,18 @@ impl<T: PortWrite> PortWriteOnly<T> {
}
}

impl<T: PortReadWrite> Port<T> {
const_fn! {
/// Creates an I/O port with the given port number.
#[inline]
pub fn new(port: u16) -> Port<T> {
Port {
port,
phantom: PhantomData,
}
impl<T> Port<T> {
/// Creates an I/O port with the given port number.
#[inline]
pub const fn new(port: u16) -> Port<T> {
Port {
port,
phantom: PhantomData,
}
}
}

impl<T: PortReadWrite> Port<T> {
/// Reads from the port.
///
/// ## Safety
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! and access to various system registers.

#![cfg_attr(not(test), no_std)]
#![cfg_attr(feature = "const_fn", feature(const_fn))]
#![cfg_attr(feature = "const_fn", feature(const_fn))] // Needed for generic access to associated consts
#![cfg_attr(feature = "const_fn", feature(const_mut_refs))]
#![cfg_attr(feature = "const_fn", feature(const_fn_fn_ptr_basics))]
#![cfg_attr(feature = "const_fn", feature(const_in_array_repeat_expressions))]
Expand Down