Why using Impl in Rust 2 times?

Viewed 197

Im a VERY new to Rust. Currently, i don't know why it is common to use Impl with the same name (description) twice like this:

#![feature(negative_impls)]
#![allow(order_dependent_trait_objects)]

// Check that the issue #33140 hack does not allow unintended things.

// OK
trait Trait0 {}

impl Trait0 for dyn Send {}
impl Trait0 for dyn Send {}

or this:

impl ClientEnv {
    pub fn new() -> ClientResult<Self> {
        let client = ClientBuilder::new()
            .build()
            .map_err(|err| Error::http_client_create_error(err))?;
            
            
... (some code here)

impl ClientEnv {
    /// Returns current Unix time in ms
    pub fn now_ms(&self) -> u64 {
        chrono::prelude::Utc::now().timestamp_millis() as u64
    }

    /// Sets timer for provided time interval
    pub async fn set_timer(&self, ms: u64) -> ClientResult<()> {
        tokio::time::delay_for(tokio::time::Duration::from_millis(ms)).await;
        Ok(())
    }

    /// Sends asynchronous task to scheduler
    pub fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
        self.async_runtime_handle


... (here the code again).

I can't find any explanation, so i think that it is just a logical divide for the same implementation.

Thanks in advance

0 Answers
Related