NEPLg2 Standard Library - io - io
Web Playground
Web Playground

io

targetたーげっと非依存ひいぞんの stream 抽象ちゅうしょうと binary buffer をあつめるライブラリ

目的もくてき

  • byte stream / text stream の能力のうりょくを trait として分離ぶんりし、std/streamiostd/io共通きょうつう入口いりぐち構築こうちくできるようにします。
  • binary stream の媒体ばいたいとして、fd_read / fd_write にそのままわたせる連続れんぞく byte buffer ByteBuf定義ていぎします。

注意ちゅうい

  • ここでは syscall や descriptor をあつかいません。具体的ぐたいてき入出力にゅうしゅつりょくstd/streamiostd/fs担当たんとうします。
  • ByteBuf所有権しょゆうけんつので Copy / Clone実装じっそうしません。
TEST
#entry main
#target std
#import "std/test" as *
#import "alloc/io" as *
struct CountSink:
    total <i32>

impl ByteWriter for CountSink:
    fn write_bytes <(CountSink,ByteBuf)*>Result<CountSink, StdErrorKind>> (sink, bytes):
        let n <i32> get bytes "len";
        io_bytebuf_free bytes;
        Result::Ok CountSink add get sink "total" n

fn main <()*>i32> ():
    let bytes0 <ByteBuf> io_bytebuf_from_str "AB";
    match io_write_bytes (CountSink 3) bytes0:
        Result::Ok sink1:
            if eq get sink1 "total" 5 0 1
        Result::Err _e:
            0

ByteBuf

連続れんぞくした raw byte buffer を所有しょゆうする handle

目的もくてき

  • Vec<u8>内部表現ないぶひょうげん依存いそんせず、binary I/O の媒体ばいたい明示的めいじてきあらわします。

注意ちゅうい

  • ptrlen byte の所有領域しょゆうりょういきします。
  • 使つかわったら io_bytebuf_free解放かいほうしてください。

ByteReader

なまバイト列ばいとれつ能力のうりょく

ByteWriter

なまバイト列ばいとれつ能力のうりょく

TextReader

text として全体ぜんたい能力のうりょく

TextWriter

text を能力のうりょく

Flush

保留中ほりゅうちゅう出力しゅつりょく外部がいぶ反映はんえいする能力のうりょく

Close

stream をじる能力のうりょく