Skip to content

Commit

Permalink
chore/docs: eliminate warnings (#2583)
Browse files Browse the repository at this point in the history
* chore: replace trim_right with $ sed -i'' 's/trim_right/trim_end/' **/*.rs

* docs: individually document macros to avoid warning, add TODO to make to_edge hygenic

* docs: document impl_array_newtype macros, refactor: move all impl_array_newtype macro traits into impl_array_netype_index
  • Loading branch information
JeremyRubin authored and ignopeverell committed Feb 15, 2019
1 parent ac6ed71 commit dc6542d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl From<Request<Body>> for QueryParams {
#[macro_export]
macro_rules! right_path_element(
($req: expr) =>(
match $req.uri().path().trim_right_matches('/').rsplit('/').next() {
match $req.uri().path().trim_end_matches('/').rsplit('/').next() {
None => return response(StatusCode::BAD_REQUEST, "invalid url"),
Some(el) => el,
};
Expand Down
6 changes: 5 additions & 1 deletion core/src/pow/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,32 @@ pub fn create_siphash_keys(header: &[u8]) -> Result<[u64; 4], Error> {
])
}

/// Macros to clean up integer unwrapping
/// Macro to clean up u64 unwrapping
#[macro_export]
macro_rules! to_u64 {
($n:expr) => {
$n.to_u64().ok_or(ErrorKind::IntegerCast)?
};
}

/// Macro to clean up u64 unwrapping as u32
#[macro_export]
macro_rules! to_u32 {
($n:expr) => {
$n.to_u64().ok_or(ErrorKind::IntegerCast)? as u32
};
}

/// Macro to clean up u64 unwrapping as usize
#[macro_export]
macro_rules! to_usize {
($n:expr) => {
$n.to_u64().ok_or(ErrorKind::IntegerCast)? as usize
};
}

/// Macro to clean up casting to edge type
/// TODO: this macro uses unhygenic data T
#[macro_export]
macro_rules! to_edge {
($n:expr) => {
Expand Down
25 changes: 14 additions & 11 deletions util/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

//! Macros to support Rust BIP-32 code (though could conceivably be used for other things)
/// gives a newtype array wrapper standard array traits
#[macro_export]
macro_rules! impl_array_newtype {
($thing:ident, $ty:ty, $len:expr) => {
Expand Down Expand Up @@ -86,16 +87,6 @@ macro_rules! impl_array_newtype {
}
}

impl ::std::ops::Index<usize> for $thing {
type Output = $ty;

#[inline]
fn index(&self, index: usize) -> &$ty {
let &$thing(ref dat) = self;
&dat[index]
}
}

impl_index_newtype!($thing, $ty);

impl PartialEq for $thing {
Expand Down Expand Up @@ -164,6 +155,7 @@ macro_rules! impl_array_newtype {
};
}

/// gives a newtype array wrapper serialization and deserialization methods
#[macro_export]
macro_rules! impl_array_newtype_encodable {
($thing:ident, $ty:ty, $len:expr) => {
Expand Down Expand Up @@ -193,7 +185,7 @@ macro_rules! impl_array_newtype_encodable {
*item = match seq.next_element()? {
Some(c) => c,
None => {
return Err($crate::serde::de::Error::custom("end of stream"))
return Err($crate::serde::de::Error::custom("end of stream"));
}
};
}
Expand All @@ -218,6 +210,7 @@ macro_rules! impl_array_newtype_encodable {
};
}

/// gives a newtype array wrapper the Debug trait
#[macro_export]
macro_rules! impl_array_newtype_show {
($thing:ident) => {
Expand All @@ -229,9 +222,19 @@ macro_rules! impl_array_newtype_show {
};
}

/// gives a newtype array wrapper Index traits
#[macro_export]
macro_rules! impl_index_newtype {
($thing:ident, $ty:ty) => {
impl ::std::ops::Index<usize> for $thing {
type Output = $ty;

#[inline]
fn index(&self, index: usize) -> &$ty {
let &$thing(ref dat) = self;
&dat[index]
}
}
impl ::std::ops::Index<::std::ops::Range<usize>> for $thing {
type Output = [$ty];

Expand Down

0 comments on commit dc6542d

Please sign in to comment.