pub struct Randoms {
    pub id: usize,
    pub numbers: Vec<u64>,
}
Expand description

This represents a simple collection of random numbers which is hosted inside the thread pool

It is tied to a particular thread by the modulus of its id.

The interface that it supports is governed by its implementation of the PoolItem trait. This in turn needs to be supported by the use of two enums of supported requests and responses

It supports the following operations Init creates a new Random with an stack based store of random numbers Mean calculates the mean of the contained numbers Sum calculates the sum of the contained numbers

Fields§

§id: usize§numbers: Vec<u64>

Implementations§

source§

impl Randoms

source

pub fn new(id: usize) -> Self

source

pub fn mean(&self) -> u128

source

#[no_mangle]
pub fn sum(&self) -> u128

Trait Implementations§

source§

impl Debug for Randoms

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl IdTargeted for Randoms

source§

fn id(&self) -> usize

source§

impl PartialEq<Randoms> for Randoms

source§

fn eq(&self, other: &Randoms) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PoolItem for Randoms

The implementation of this trait allows the Randoms struct to be used in the thread pool infrastructure

§

type Init = RandomsAddRequest

This is a struct that defines the message that will initiate a new instance of the struct within the thread pool
§

type Api = RandomsApi

This is the enum that will define that messaging api that can be used to communicate with instances of the struct It will be an enum where each variant will define a request/response pair of structs
source§

fn name() -> &'static str

used for debug only; allows logging to output the name of the type
source§

fn process_message(&mut self, request: Self::Api) -> ThreadRequestResponse<Self>

This is the function that will define how the struct processes the messages that it receives. It will typically consist of a match statement that will discriminate amongst the various messages type defined in the Api
source§

fn add_pool_item_tracing(&self) -> Option<Vec<Box<dyn GuardDrop>>>

This method is called to optionally add tracing before each message is processed. The tracing is removed once the message is processed. If the tracing is being written to a file it is important that the file is not truncated The implementation needs to return a vec of guards of any subscribers added.
source§

fn new_pool_item(request: Self::Init) -> Result<Self, NewPoolItemError>

This function defines how a new struct will be created when it receives The Init message. It returns the created new instance of the struct
source§

fn shutdown_pool(&self) -> Vec<ThreadShutdownResponse>

This function is a hook that is called when the pool is shutting down.
source§

fn id_not_found(request: &Self::Api) -> ThreadRequestResponse<Self>

The function called if an item with the specified is not found The default behaviour is to panic
source§

fn add_pool_thread_tracing( id: usize ) -> Option<(DefaultGuard, Vec<WorkerGuard>)>

This method provides any required tracing in the pool items thread pool threads This tracing is added when the thread is spawned and remains in place until the thread dies
source§

impl RequestWithResponse<Randoms> for MeanRequest

ties together the request with a response

source§

impl RequestWithResponse<Randoms> for PanicRequest

ties together the request with a response

source§

impl RequestWithResponse<Randoms> for RandomsAddRequest

source§

impl RequestWithResponse<Randoms> for SumRequest

ties together the request with a response

source§

impl Eq for Randoms

source§

impl StructuralEq for Randoms

source§

impl StructuralPartialEq for Randoms

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more