LoginSignup
0
0

Rust+Hyper Shift_JIS でレスポンスを返却する

Last updated at Posted at 2023-09-14
fn full<T: Into<Bytes>>(chunk: T) -> BoxBody {
    Full::new(chunk.into())
        .map_err(|never| match never {})
        .boxed()
}

fn index() -> Result<Response<BoxBody>> {
    let cow_of_shift_jis_u8 = SHIFT_JIS.encode("あいうえお"); // encoding_rs::SHIFT_JIS encoding-rs crate

    Ok(Response::builder()
        .header("Content-Type", "text/plain; charset=shift_jis")
        .status(StatusCode::OK)
        .body(full(cow_of_shift_jis_u8.0.into_owned().into_boxed_slice()))?)
}

into_owned で Vec<u8> にして、into_boxed_slice で Box<[u8]> に変換

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0