Skip to main content

CodecDispatcher

Trait CodecDispatcher 

Source
pub trait CodecDispatcher: Send + Sync {
    // Required method
    fn pick<'life0, 'life1, 'async_trait>(
        &'life0 self,
        sample: &'life1 [u8],
    ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn pick_with_size_hint<'life0, 'life1, 'async_trait>(
        &'life0 self,
        sample: &'life1 [u8],
        _total_size: Option<u64>,
    ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

PUT body の先頭 sample から codec を選ぶ trait。

v0.8 #56: 呼び出し側が Content-Length を知っている場合 (chunked transfer でない通常 PUT)、pick_with_size_hint 経由で total body size を渡せる。 SamplingDispatcher は GPU upload overhead が compress 時間を上回る小オブ ジェクトで CPU codec を選び、十分大きい (>= gpu_min_bytes) ものでだけ GPU codec へ昇格させる。size hint が None (chunked transfer) の場合は 保守的に CPU 側に倒す。

既定実装は pick_with_size_hint(sample, None)pick(sample) に委譲する — 既存 implementor は pick だけ実装すれば従来通り動く。

Required Methods§

Source

fn pick<'life0, 'life1, 'async_trait>( &'life0 self, sample: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Provided Methods§

Source

fn pick_with_size_hint<'life0, 'life1, 'async_trait>( &'life0 self, sample: &'life1 [u8], _total_size: Option<u64>, ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

v0.8 #56: size-hint aware pick. 既定実装は pick(sample) に委譲する ので、追加情報を活用する dispatcher (SamplingDispatcher) のみ override すればよい。total_size = None は「chunked transfer で content-length が無い」ケースを表す。

Implementations on Foreign Types§

Source§

impl<T: CodecDispatcher + ?Sized> CodecDispatcher for Box<T>

Box<dyn CodecDispatcher> からも CodecDispatcher として使えるようにする blanket impl

Source§

fn pick<'life0, 'life1, 'async_trait>( &'life0 self, sample: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn pick_with_size_hint<'life0, 'life1, 'async_trait>( &'life0 self, sample: &'life1 [u8], total_size: Option<u64>, ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

impl<T: CodecDispatcher + ?Sized> CodecDispatcher for Arc<T>

Source§

fn pick<'life0, 'life1, 'async_trait>( &'life0 self, sample: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn pick_with_size_hint<'life0, 'life1, 'async_trait>( &'life0 self, sample: &'life1 [u8], total_size: Option<u64>, ) -> Pin<Box<dyn Future<Output = CodecKind> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§