lints
This commit is contained in:
@@ -26,6 +26,12 @@ impl EventualBase for Eventual {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Eventual {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Eventual {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@@ -39,7 +45,7 @@ impl Eventual {
|
||||
{
|
||||
EventualFutureClone {
|
||||
id: None,
|
||||
value: value,
|
||||
value,
|
||||
eventual: self.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<T> EventualBaseInner<T> {
|
||||
self.wakers.remove(&id);
|
||||
// See if we should complete the EventualResolvedFutures
|
||||
let mut resolved_waker_list = Vec::new();
|
||||
if self.wakers.len() == 0 && self.resolved.is_some() {
|
||||
if self.wakers.is_empty() && self.resolved.is_some() {
|
||||
for w in &self.resolved_wakers {
|
||||
resolved_waker_list.push(w.1.clone());
|
||||
}
|
||||
@@ -92,26 +92,25 @@ impl<T> EventualBaseInner<T> {
|
||||
self.resolved_freelist.clear();
|
||||
}
|
||||
|
||||
pub(super) fn try_reset(&mut self) -> Result<(), ()> {
|
||||
if self.wakers.len() != 0 {
|
||||
return Err(());
|
||||
pub(super) fn try_reset(&mut self) -> Result<(), String> {
|
||||
if !self.wakers.is_empty() {
|
||||
return Err("Wakers not empty during reset".to_owned());
|
||||
}
|
||||
if self.resolved_wakers.len() != 0 {
|
||||
return Err(());
|
||||
if !self.resolved_wakers.is_empty() {
|
||||
return Err("Resolved wakers not empty during reset".to_owned());
|
||||
}
|
||||
self.reset();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Resolved future helpers
|
||||
#[must_use]
|
||||
pub(super) fn resolved_poll(
|
||||
&mut self,
|
||||
id: &mut Option<usize>,
|
||||
cx: &mut task::Context<'_>,
|
||||
) -> task::Poll<()> {
|
||||
// If there are any instance futures still waiting, we resolution isn't finished
|
||||
if self.wakers.len() != 0 {
|
||||
if !self.wakers.is_empty() {
|
||||
if id.is_none() {
|
||||
*id = Some(self.insert_resolved_waker(cx.waker().clone()));
|
||||
}
|
||||
@@ -137,12 +136,10 @@ impl<T> EventualBaseInner<T> {
|
||||
*id = Some(self.insert_waker(cx.waker().clone()));
|
||||
}
|
||||
None
|
||||
} else if let Some(id) = id.take() {
|
||||
Some(self.remove_waker(id))
|
||||
} else {
|
||||
if let Some(id) = id.take() {
|
||||
Some(self.remove_waker(id))
|
||||
} else {
|
||||
Some(Vec::new())
|
||||
}
|
||||
Some(Vec::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,7 +199,7 @@ pub trait EventualCommon: EventualBase {
|
||||
self.base_inner().reset()
|
||||
}
|
||||
|
||||
fn try_reset(&self) -> Result<(), ()> {
|
||||
fn try_reset(&self) -> Result<(), String> {
|
||||
self.base_inner().try_reset()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,12 @@ impl<T: Unpin> EventualBase for EventualValue<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Unpin> Default for EventualValue<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Unpin> EventualValue<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
@@ -26,6 +26,12 @@ impl<T: Unpin + Clone> EventualBase for EventualValueClone<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Unpin + Clone> Default for EventualValueClone<T> {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Unpin + Clone> EventualValueClone<T> {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
||||
@@ -8,10 +8,7 @@ pub struct IpAddrPort {
|
||||
|
||||
impl IpAddrPort {
|
||||
pub fn new(addr: IpAddr, port: u16) -> Self {
|
||||
Self {
|
||||
addr: addr,
|
||||
port: port,
|
||||
}
|
||||
Self { addr, port }
|
||||
}
|
||||
pub fn addr(&self) -> &IpAddr {
|
||||
&self.addr
|
||||
|
||||
@@ -63,17 +63,14 @@ pub fn ipv4addr_is_loopback(addr: &Ipv4Addr) -> bool {
|
||||
pub fn ipv4addr_is_private(addr: &Ipv4Addr) -> bool {
|
||||
match addr.octets() {
|
||||
[10, ..] => true,
|
||||
[172, b, ..] if b >= 16 && b <= 31 => true,
|
||||
[172, b, ..] if (16..=31).contains(&b) => true,
|
||||
[192, 168, ..] => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ipv4addr_is_link_local(addr: &Ipv4Addr) -> bool {
|
||||
match addr.octets() {
|
||||
[169, 254, ..] => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(addr.octets(), [169, 254, ..])
|
||||
}
|
||||
|
||||
pub fn ipv4addr_is_global(addr: &Ipv4Addr) -> bool {
|
||||
@@ -120,12 +117,10 @@ pub fn ipv4addr_is_broadcast(addr: &Ipv4Addr) -> bool {
|
||||
}
|
||||
|
||||
pub fn ipv4addr_is_documentation(addr: &Ipv4Addr) -> bool {
|
||||
match addr.octets() {
|
||||
[192, 0, 2, _] => true,
|
||||
[198, 51, 100, _] => true,
|
||||
[203, 0, 113, _] => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(
|
||||
addr.octets(),
|
||||
[192, 0, 2, _] | [198, 51, 100, _] | [203, 0, 113, _]
|
||||
)
|
||||
}
|
||||
|
||||
pub fn ipv6addr_is_unspecified(addr: &Ipv6Addr) -> bool {
|
||||
@@ -149,10 +144,10 @@ pub fn ipv6addr_is_unique_local(addr: &Ipv6Addr) -> bool {
|
||||
}
|
||||
|
||||
pub fn ipv6addr_is_unicast_link_local_strict(addr: &Ipv6Addr) -> bool {
|
||||
(addr.segments()[0] & 0xffff) == 0xfe80
|
||||
&& (addr.segments()[1] & 0xffff) == 0
|
||||
&& (addr.segments()[2] & 0xffff) == 0
|
||||
&& (addr.segments()[3] & 0xffff) == 0
|
||||
addr.segments()[0] == 0xfe80
|
||||
&& addr.segments()[1] == 0
|
||||
&& addr.segments()[2] == 0
|
||||
&& addr.segments()[3] == 0
|
||||
}
|
||||
|
||||
pub fn ipv6addr_is_unicast_link_local(addr: &Ipv6Addr) -> bool {
|
||||
|
||||
@@ -56,8 +56,8 @@ where
|
||||
|
||||
fn unlock(&self, jh: Option<JoinHandle<T>>) {
|
||||
let mut inner = self.inner.lock();
|
||||
assert_eq!(inner.locked, true);
|
||||
assert_eq!(inner.join_handle.is_none(), true);
|
||||
assert!(inner.locked);
|
||||
assert!(inner.join_handle.is_none());
|
||||
inner.locked = false;
|
||||
inner.join_handle = jh;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ where
|
||||
pub fn new(drop_value: T) -> Self {
|
||||
Self {
|
||||
eventual: EventualValueClone::new(),
|
||||
drop_value: drop_value,
|
||||
drop_value,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ impl TickTask {
|
||||
pub fn new_us(tick_period_us: u64) -> Self {
|
||||
Self {
|
||||
last_timestamp_us: AtomicU64::new(0),
|
||||
tick_period_us: tick_period_us,
|
||||
tick_period_us,
|
||||
routine: OnceCell::new(),
|
||||
single_future: SingleFuture::new(),
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
use crate::xx::*;
|
||||
use alloc::string::ToString;
|
||||
|
||||
pub fn split_port(name: &str) -> Result<(String, u16), ()> {
|
||||
pub fn split_port(name: &str) -> Result<(String, Option<u16>), String> {
|
||||
if let Some(split) = name.rfind(':') {
|
||||
let hoststr = &name[0..split];
|
||||
let portstr = &name[split + 1..];
|
||||
let port: u16 = portstr.parse::<u16>().map_err(drop)?;
|
||||
let port: u16 = portstr
|
||||
.parse::<u16>()
|
||||
.map_err(|e| format!("Invalid port: {}", e))?;
|
||||
|
||||
Ok((hoststr.to_string(), port))
|
||||
Ok((hoststr.to_string(), Some(port)))
|
||||
} else {
|
||||
Err(())
|
||||
Ok((name.to_string(), None))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepend_slash(s: String) -> String {
|
||||
if s.starts_with("/") {
|
||||
if s.starts_with('/') {
|
||||
return s;
|
||||
}
|
||||
let mut out = "/".to_owned();
|
||||
|
||||
Reference in New Issue
Block a user