Skip to main content

RequestCommon

Trait RequestCommon 

Source
pub trait RequestCommon:
    Serialize
    + Deserialize
    + Send
    + Sync
    + Unpin
    + Debug
    + 'static {
    type Kind: RequestKind;
    type Response: Deserialize + Serialize + Send;

    const TYPE_ID: u16;
    const MAX_REQUESTS: u32;
    const TIME_WINDOW: Duration = DEFAULT_MAX_REQUEST_RESPONSE_TIME_WINDOW;

    // Provided method
    fn type_name<T>() -> &'static str { ... }
}

Required Associated Constants§

Source

const TYPE_ID: u16

Source

const MAX_REQUESTS: u32

The maximum number of requests of this type a peer can send in a burst. Implementations treat the budget as a token bucket that refills one request every TIME_WINDOW / MAX_REQUESTS, so this is also the number of requests a peer can make per TIME_WINDOW on average. A request that finds the bucket empty is answered with InboundRequestError::ExceedsRateLimit. Must be at least one.

Provided Associated Constants§

Source

const TIME_WINDOW: Duration = DEFAULT_MAX_REQUEST_RESPONSE_TIME_WINDOW

The time it takes to refill the whole budget of MAX_REQUESTS. Must be at least a nanosecond per request, so it cannot be zero.

Required Associated Types§

Provided Methods§

Source

fn type_name<T>() -> &'static str

Returns the type name of the given request type T. This only works for

  • non-generic types
  • generic types with a single level of nesting, in which case the name of the type parameter is returned

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§