Skip to content

Commit

Permalink
remove unnecessary set_resource_id method
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 20, 2023
1 parent 19ea32e commit f86a594
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 5 additions & 23 deletions src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ pub enum TransportState {
/// Error indicating that method [`NetTransport::set_resource_id`] was called more than once.
#[derive(Copy, Clone, Eq, PartialEq, Debug, Display, Error)]
#[display("an attempt to re-assign resource id to {new} for net transport {current}.")]
pub struct ResIdReassigned { current: ResourceId, new: ResourceId }
pub struct ResIdReassigned {
current: ResourceId,
new: ResourceId,
}

/// Net transport is an adaptor around specific [`NetSession`] (implementing
/// session management, including optional handshake, encoding etc) to be used
Expand All @@ -215,8 +218,6 @@ pub struct NetTransport<S: NetSession> {
write_intent: bool,
read_buffer: Box<[u8; HEAP_BUFFER_SIZE]>,
write_buffer: VecDeque<u8>,
/// Resource id assigned by the reactor
id: Option<ResourceId>
}

impl<S: NetSession> Display for NetTransport<S> {
Expand Down Expand Up @@ -260,7 +261,6 @@ impl<S: NetSession> NetTransport<S> {
write_intent: true,
read_buffer: Box::new([0u8; READ_BUFFER_SIZE]),
write_buffer: empty!(),
id: None,
})
}

Expand Down Expand Up @@ -300,28 +300,10 @@ impl<S: NetSession> NetTransport<S> {
write_intent: false,
read_buffer: Box::new([0u8; READ_BUFFER_SIZE]),
write_buffer: empty!(),
id: None,
})
}

pub fn display(&self) -> impl Display {
match self.id {
None => self.session.display(),
Some(id) => id.to_string()
}
}

pub fn resource_id(&self) -> Option<ResourceId> {
self.id
}

pub fn set_resource_id(&mut self, id: ResourceId) -> Result<(), ResIdReassigned> {
if let Some(current) = self.id {
return Err(ResIdReassigned { current, new: id })
}
self.id = Some(id);
Ok(())
}
pub fn display(&self) -> impl Display { self.session.display() }

pub fn state(&self) -> TransportState { self.state }
pub fn is_active(&self) -> bool { self.state == TransportState::Active }
Expand Down

0 comments on commit f86a594

Please sign in to comment.