Struct Counter

Source
pub struct Counter(pub usize);
Expand description

A Collection that only counts the final size of a set operation.

It is meant to be used to avoid unecessary allocations.

use sdset::duo::OpBuilder;
use sdset::{SetOperation, Set, SetBuf, Counter};

let a = Set::new(&[1, 2, 4, 6, 7])?;
let b = Set::new(&[2, 3, 4, 5, 6, 7])?;

let op = OpBuilder::new(a, b).union();

let mut counter = Counter::default();
SetOperation::<i32>::extend_collection(op, &mut counter);

assert_eq!(counter.0, 7);

Tuple Fields§

§0: usize

Implementations§

Source§

impl Counter

Source

pub fn new() -> Counter

Create a new Counter initialized with 0;

Trait Implementations§

Source§

impl<T> Collection<T> for Counter

Source§

fn push(&mut self, _elem: T)

Insert one element into the collection.
Source§

fn extend_from_slice(&mut self, elems: &[T])
where T: Clone,

Extend the collection by cloning the elements.
Source§

fn extend<I>(&mut self, elems: I)
where I: IntoIterator<Item = T>,

Extend the collection by inserting the elements from the given Iterator.
Source§

fn reserve(&mut self, _size: usize)

Reserve enough space in the collection for size elements.
Source§

impl Default for Counter

Source§

fn default() -> Counter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.