Skip to content

Commit

Permalink
fix: use impl From<RangeInclusive> for FilterBlockOption instead of…
Browse files Browse the repository at this point in the history
… `Range` (#1199)

* use RangeInclusive instead on From for FilterBlockOption

* fix doctests
  • Loading branch information
joshieDo authored Aug 26, 2024
1 parent 02ccb77 commit 2242ac8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{
HashSet,
},
hash::Hash,
ops::{Range, RangeFrom, RangeTo},
ops::{RangeFrom, RangeInclusive, RangeToInclusive},
};
use thiserror::Error;

Expand Down Expand Up @@ -277,16 +277,17 @@ impl From<u64> for FilterBlockOption {
}
}

impl<T: Into<BlockNumberOrTag>> From<Range<T>> for FilterBlockOption {
fn from(r: Range<T>) -> Self {
let from_block = Some(r.start.into());
let to_block = Some(r.end.into());
impl<T: Into<BlockNumberOrTag>> From<RangeInclusive<T>> for FilterBlockOption {
fn from(r: RangeInclusive<T>) -> Self {
let (start, end) = r.into_inner();
let from_block = Some(start.into());
let to_block = Some(end.into());
Self::Range { from_block, to_block }
}
}

impl<T: Into<BlockNumberOrTag>> From<RangeTo<T>> for FilterBlockOption {
fn from(r: RangeTo<T>) -> Self {
impl<T: Into<BlockNumberOrTag>> From<RangeToInclusive<T>> for FilterBlockOption {
fn from(r: RangeToInclusive<T>) -> Self {
let to_block = Some(r.end.into());
Self::Range { from_block: Some(BlockNumberOrTag::Earliest), to_block }
}
Expand Down Expand Up @@ -371,7 +372,7 @@ impl Filter {
/// ```rust
/// # use alloy_rpc_types_eth::Filter;
/// # fn main() {
/// let filter = Filter::new().select(0u64..100u64);
/// let filter = Filter::new().select(0u64..=100u64);
/// # }
/// ```
///
Expand All @@ -389,7 +390,7 @@ impl Filter {
/// ```rust
/// # use alloy_rpc_types_eth::Filter;
/// # fn main() {
/// let filter = Filter::new().select(..1337u64);
/// let filter = Filter::new().select(..=1337u64);
/// # }
/// ```
#[must_use]
Expand Down

0 comments on commit 2242ac8

Please sign in to comment.