From 02276934a9db2f361e1bd2ffc9d18688e951eccc Mon Sep 17 00:00:00 2001 From: Guest0x0 Date: Mon, 2 Mar 2026 04:05:45 +0000 Subject: [PATCH] remove some deprecated stuff --- src/async.mbt | 14 -- src/fs/file.mbt | 30 --- src/fs/pkg.generated.mbti | 6 - src/http/client.mbt | 26 +-- src/http/pkg.generated.mbti | 23 +- src/http/request.mbt | 50 ++--- src/http/server.mbt | 40 ---- src/io/README.mbt.md | 1 - src/io/buffered_reader.mbt | 162 -------------- src/io/buffered_reader_wbtest.mbt | 350 ------------------------------ src/io/pkg.generated.mbti | 13 -- src/io/writer.mbt | 9 - src/pkg.generated.mbti | 7 - src/socket/pkg.generated.mbti | 2 - src/socket/tcp.mbt | 2 - src/task_group.mbt | 4 - src/tls/openssl.mbt | 1 - src/tls/pkg.generated.mbti | 1 - 18 files changed, 21 insertions(+), 720 deletions(-) delete mode 100644 src/io/buffered_reader_wbtest.mbt diff --git a/src/async.mbt b/src/async.mbt index 66db9dc4..4c32da38 100644 --- a/src/async.mbt +++ b/src/async.mbt @@ -12,20 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -///| -/// Create a fresh event loop and run a async program inside the loop. -/// A new task group will be created for convenience, -/// that is, `with_event_loop(f)` will run `with_task_group(f)` using the event loop. -/// -/// There can only one event loop running for every program, -/// calling `with_event_loop` inside another event loop is invalid, -/// and will result in immediate failure. -#deprecated("use `async fn main` or `async test` instead") -#cfg(target="native") -pub fn with_event_loop(f : async (TaskGroup[Unit]) -> Unit) -> Unit raise { - @event_loop.with_event_loop(() => with_task_group(f)) -} - ///| /// `sleep` will wait for the given time (in milliseconds) before returning. /// Other task can still run while current task is sleeping. diff --git a/src/fs/file.mbt b/src/fs/file.mbt index 0e20028f..f90279dc 100644 --- a/src/fs/file.mbt +++ b/src/fs/file.mbt @@ -393,17 +393,6 @@ pub async fn read_file( result } -///| -/// Read the contents of a text file located at `path`. -#deprecated("use `read_file(path).text()` instead") -pub async fn read_text_file( - path : StringView, - encoding~ : @io.Encoding, -) -> String { - guard encoding is UTF8 - read_file(path).text() -} - ///| /// Write data to a file located at `path`. /// The meaning of `sync`, `append`, `create`, and `truncate`, @@ -421,22 +410,3 @@ pub async fn write_file( defer file.close() file.write(content.binary()) } - -///| -/// Write data to a text file located at `path`. -/// The meaning of `sync`, `append`, `create`, truncate` is the same as `open`, -/// except that `truncate` is `true` by default. See `open` for more details. -#deprecated("use `write_file(path, content)` instead") -pub async fn write_text_file( - path : StringView, - content : String, - encoding~ : @io.Encoding, - sync? : SyncMode = Data, - append? : Bool = false, - create? : Int, - truncate? : Bool = true, -) -> Unit { - let file = open(path, mode=WriteOnly, sync~, append~, create?, truncate~) - defer file.close() - file.write_string(content, encoding~) -} diff --git a/src/fs/pkg.generated.mbti b/src/fs/pkg.generated.mbti index b60e06b7..ac7ca24a 100644 --- a/src/fs/pkg.generated.mbti +++ b/src/fs/pkg.generated.mbti @@ -34,9 +34,6 @@ pub async fn opendir(StringView) -> Directory pub async fn read_file(StringView, sync_timestamp? : Bool) -> &@io.Data -#deprecated -pub async fn read_text_file(StringView, encoding~ : @io.Encoding) -> String - pub async fn readdir(StringView, include_hidden? : Bool, include_special? : Bool, sort? : Bool) -> Array[String] pub async fn realpath(StringView) -> String @@ -53,9 +50,6 @@ pub async fn walk(StringView, async (String, Array[String]) -> Unit, exclude? : pub async fn write_file(StringView, &@io.Data, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> Unit -#deprecated -pub async fn write_text_file(StringView, String, encoding~ : @io.Encoding, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> Unit - // Errors // Types and methods diff --git a/src/http/client.mbt b/src/http/client.mbt index 06317a39..ee7414ec 100644 --- a/src/http/client.mbt +++ b/src/http/client.mbt @@ -35,31 +35,7 @@ pub suberror ProxyError { } derive(Show, ToJson) ///| -/// Create a new HTTP client by connecting to a remote host. -/// If `protocol` is `Https` (`Https` by default), -/// a TLS connection will be established, -/// and the certificate of the remote peer will be verified. -/// -/// `headers` can be used to specify persistent headers for the client, -/// i.e. all requests made from this client will share these headers. -/// The ownership of `headers` will be transferred to the new client, -/// so `headers` should not be used by the caller later. -/// The following headers is automatically set, -/// and must not be specified in `headers`: -/// -/// - Host -/// - Content-Length, Transfer-Encoding -/// -/// If `proxy` is present, it should be another HTTP client in a clean state. -/// The new client will send a `CONNECT` request via the proxy client -/// and try to establish a tunnel via the proxy client. -/// All subsequent requests made by the new client will go through the proxy tunnel. -/// The ownership of the proxy client is transferred to the new client, -/// so it must not be used nor closed anymore by the caller. -/// Using another HTTP client as proxy allows advanced features such as -/// proxy authentication and https `CONNECT` proxy. -#deprecated("use `@http.Client::new()` and specify protocol/port in the URI instead", skip_current_package=true) -pub async fn Client::connect( +async fn Client::connect( host : String, headers? : Map[String, String] = {}, protocol? : Protocol = Https, diff --git a/src/http/pkg.generated.mbti b/src/http/pkg.generated.mbti index 3ebffb06..d3dcbcde 100644 --- a/src/http/pkg.generated.mbti +++ b/src/http/pkg.generated.mbti @@ -7,26 +7,17 @@ import { } // Values -#label_migration(port, fill=false, msg="specify the port in URI instead") -pub async fn get(String, headers? : Map[String, String], port? : Int, body? : &@io.Data, proxy? : Client) -> (Response, &@io.Data) +pub async fn get(String, headers? : Map[String, String], body? : &@io.Data, proxy? : Client) -> (Response, &@io.Data) -#label_migration(port, fill=false, msg="specify the port in URI instead") -pub async fn get_stream(String, headers? : Map[String, String], port? : Int, body? : &@io.Data, proxy? : Client) -> (Response, Client) +pub async fn get_stream(String, headers? : Map[String, String], body? : &@io.Data, proxy? : Client) -> (Response, Client) -#label_migration(port, fill=false, msg="specify the port in URI instead") -pub async fn post(String, &@io.Data, headers? : Map[String, String], port? : Int, proxy? : Client) -> (Response, &@io.Data) +pub async fn post(String, &@io.Data, headers? : Map[String, String], proxy? : Client) -> (Response, &@io.Data) -#label_migration(port, fill=false, msg="specify the port in URI instead") -pub async fn post_stream(String, headers? : Map[String, String], port? : Int, proxy? : Client) -> Client +pub async fn post_stream(String, headers? : Map[String, String], proxy? : Client) -> Client -#label_migration(port, fill=false, msg="specify the port in URI instead") -pub async fn put(String, &@io.Data, headers? : Map[String, String], port? : Int, proxy? : Client) -> (Response, &@io.Data) +pub async fn put(String, &@io.Data, headers? : Map[String, String], proxy? : Client) -> (Response, &@io.Data) -#label_migration(port, fill=false, msg="specify the port in URI instead") -pub async fn put_stream(String, headers? : Map[String, String], port? : Int, proxy? : Client) -> Client - -#deprecated -pub async fn run_server(@socket.Addr, async (ServerConnection, @socket.Addr) -> Unit, headers? : Map[String, String], dual_stack? : Bool, reuse_addr? : Bool, allow_failure? : Bool, max_connections? : Int) -> Unit +pub async fn put_stream(String, headers? : Map[String, String], proxy? : Client) -> Client // Errors pub suberror HttpProtocolError { @@ -53,8 +44,6 @@ pub impl ToJson for URIParseError // Types and methods type Client pub fn Client::close(Self) -> Unit -#deprecated -pub async fn Client::connect(String, headers? : Map[String, String], protocol? : Protocol, port? : Int, proxy? : Self) -> Self pub async fn Client::end_request(Self) -> Response pub async fn Client::enter_passthrough_mode(Self) -> Unit pub async fn Client::flush(Self) -> Unit diff --git a/src/http/request.mbt b/src/http/request.mbt index 92f39423..636c7cae 100644 --- a/src/http/request.mbt +++ b/src/http/request.mbt @@ -33,10 +33,7 @@ pub suberror URIParseError { } derive(Show, ToJson) ///| -fn resolve_url( - uri : String, - port? : Int, -) -> (Protocol, Int, String, String) raise { +fn resolve_url(uri : String) -> (Protocol, Int, String, String) raise { guard uri.find("://") is Some(protocol_len) else { raise InvalidFormat } let protocol = match uri[:protocol_len] { "http" => Http @@ -49,18 +46,12 @@ fn resolve_url( } else { (uri.to_string(), "/") } - let (host, port) = match port { - Some(port) => (host, port) - None => - if host lexmatch? (host, ":" ("[0-9]+" as port_str)) { - let port = @strconv.parse_int(port_str) catch { - _ => raise InvalidFormat - } - guard port is (1..<65536) else { raise InvalidFormat } - (host.to_string(), port) - } else { - (host, protocol.default_port()) - } + let (host, port) = if host lexmatch? (host, ":" ("[0-9]+" as port_str)) { + let port = @strconv.parse_int(port_str) catch { _ => raise InvalidFormat } + guard port is (1..<65536) else { raise InvalidFormat } + (host.to_string(), port) + } else { + (host, protocol.default_port()) } let path = if path == "" { "/" } else { path } (protocol, port, host, path) @@ -72,10 +63,9 @@ async fn perform_request( meth : RequestMethod, headers : Map[String, String], body : &@io.Data, - port? : Int, proxy? : Client, ) -> (Response, &@io.Data) { - let (protocol, port, host, path) = resolve_url(uri, port?) + let (protocol, port, host, path) = resolve_url(uri) let client = Client::connect(host, headers~, protocol~, port~, proxy?) defer client.close() let response = client..request(meth, path)..write(body).end_request() @@ -92,41 +82,35 @@ async fn perform_request( /// `proxy` is not supported on JavaScript backend. /// /// See `Client::request` for more details. -#callsite(migration(port, fill=false, msg="specify the port in URI instead")) pub async fn get( uri : String, headers? : Map[String, String] = {}, - port? : Int, body? : &@io.Data = b"", proxy? : Client, ) -> (Response, &@io.Data) { - perform_request(uri, Get, headers, body, port?, proxy?) + perform_request(uri, Get, headers, body, proxy?) } ///| /// Similar to `get`, but performs a `PUT` request instead. -#callsite(migration(port, fill=false, msg="specify the port in URI instead")) pub async fn put( uri : String, content : &@io.Data, headers? : Map[String, String] = {}, - port? : Int, proxy? : Client, ) -> (Response, &@io.Data) { - perform_request(uri, Put, headers, content, port?, proxy?) + perform_request(uri, Put, headers, content, proxy?) } ///| /// Similar to `get`, but performs a `POST` request instead. -#callsite(migration(port, fill=false, msg="specify the port in URI instead")) pub async fn post( uri : String, content : &@io.Data, headers? : Map[String, String] = {}, - port? : Int, proxy? : Client, ) -> (Response, &@io.Data) { - perform_request(uri, Post, headers, content, port?, proxy?) + perform_request(uri, Post, headers, content, proxy?) } ///| @@ -139,15 +123,13 @@ pub async fn post( /// /// Note that the returned client must be manually closed via `.close()` /// to close the underlying connection used for the request. -#callsite(migration(port, fill=false, msg="specify the port in URI instead")) pub async fn get_stream( uri : String, headers? : Map[String, String] = {}, - port? : Int, body? : &@io.Data = b"", proxy? : Client, ) -> (Response, Client) { - let (protocol, port, host, path) = resolve_url(uri, port?) + let (protocol, port, host, path) = resolve_url(uri) let client = Client::connect(host, headers~, protocol~, port~, proxy?) try { let response = client..request(Get, path)..write(body).end_request() @@ -173,14 +155,12 @@ pub async fn get_stream( /// /// Note that the returned `client` must be manually closed via `.close()` /// to close the underlying connection used for the request. -#callsite(migration(port, fill=false, msg="specify the port in URI instead")) pub async fn put_stream( uri : String, headers? : Map[String, String] = {}, - port? : Int, proxy? : Client, ) -> Client { - let (protocol, port, host, path) = resolve_url(uri, port?) + let (protocol, port, host, path) = resolve_url(uri) let client = Client::connect(host, headers~, protocol~, port~, proxy?) try client.request(Put, path) catch { err => { @@ -205,14 +185,12 @@ pub async fn put_stream( /// /// Note that the returned `client` must be manually closed via `.close()` /// to close the underlying connection used for the request. -#callsite(migration(port, fill=false, msg="specify the port in URI instead")) pub async fn post_stream( uri : String, headers? : Map[String, String] = {}, - port? : Int, proxy? : Client, ) -> Client { - let (protocol, port, host, path) = resolve_url(uri, port?) + let (protocol, port, host, path) = resolve_url(uri) let client = Client::connect(host, headers~, protocol~, port~, proxy?) try client.request(Post, path) catch { err => { diff --git a/src/http/server.mbt b/src/http/server.mbt index e6b8abf6..52156352 100644 --- a/src/http/server.mbt +++ b/src/http/server.mbt @@ -145,46 +145,6 @@ pub async fn ServerConnection::send_response( self.sender.send_response(code, reason, extra_headers~) } -///| -/// Create a HTTP server listening on `addr` and run its main loop. -/// New connections are handled by the callback `f`, -/// `f` will receive the new HTTP connection and the address of the client. -/// -/// The client connection is closed automatically, -/// so `f` must not close the connection manually. -/// -/// `headers` can be used to specify persistent headers for the server, -/// i.e. all response sent by this server will share these headers. -/// -/// If `allow_failure` is `true` (`true` by default), -/// failure in `f` will be silently ignored. -/// -/// If `max_connections` is present, -/// at most `max_connections` clients are allowed in parallel. -/// New clients will only get handled after a previous client terminates. -/// -/// The meaning of `dual_stack` and `reuse_addr` is the same as `@socket.TcpServer::new`, -/// see its document for more details. -#deprecated("use `@http.Server::run_forever()` instead") -pub async fn run_server( - addr : @socket.Addr, - f : async (ServerConnection, @socket.Addr) -> Unit, - headers? : Map[String, String], - dual_stack? : Bool, - reuse_addr? : Bool, - allow_failure? : Bool, - max_connections? : Int, -) -> Unit { - @socket.TcpServer::new(addr, dual_stack?, reuse_addr?).run_forever( - allow_failure?, - max_connections?, - (conn, addr) => { - let conn = ServerConnection::new(conn, headers?) - f(conn, addr) - }, - ) -} - ///| /// A HTTP server struct Server { diff --git a/src/io/README.mbt.md b/src/io/README.mbt.md index 7e703b88..a8797da2 100644 --- a/src/io/README.mbt.md +++ b/src/io/README.mbt.md @@ -580,7 +580,6 @@ Trait for writing data to a destination. Methods include: - `write_once(data, offset~, len~)` - Single write operation - `write(data)` - Write data (may require multiple operations) - `write_reader(reader)` - Copy data from reader to writer -- `write_string(str, encoding~)` - Write string with encoding (deprecated) ### Data diff --git a/src/io/buffered_reader.mbt b/src/io/buffered_reader.mbt index eeff985c..13596db8 100644 --- a/src/io/buffered_reader.mbt +++ b/src/io/buffered_reader.mbt @@ -66,165 +66,3 @@ async fn[R : Reader] ReaderBuffer::find_opt( continue len - target_len + 1 } } - -///| -/// A buffered wrapper around a normal reader. -/// This reader will buffer already read content, -/// and supports searching & arbitrary slicing of read content. -#deprecated("readers are now always buffered", skip_current_package=true) -struct BufferedReader[R](R) - -///| -/// Create a new buffered reader that wrap around an existing reader. -pub fn[R] BufferedReader::new(reader : R) -> BufferedReader[R] { - reader -} - -///| -/// Make sure at least `len` bytes of data are buffered, -/// read from the underlying reader if necessary. -/// The actual amount of data fetched may be larger than `len`. -/// Returns `true` if data are successfully fetched, -/// or `false` if the underlying reader already reached EOF. -async fn[R : Reader] BufferedReader::try_ensure( - self : Self[R], - len : Int, -) -> Bool { - self._get_internal_buffer().try_ensure(len, reader=self.0) -} - -///| -async fn[R : Reader] BufferedReader::ensure(self : Self[R], len : Int) -> Unit { - if !self.try_ensure(len) { - raise ReaderClosed - } -} - -///| -/// `reader.drop(n)` drops the first `n` bytes of data in the reader. -/// If there are no enough data to drop, -/// `BufferedReader` will request more data from the inner reader. -/// If the inner reader is closed before enough data is available, -/// `ReaderClosed` will be raised. -/// -/// This operation will advance the reader stream, -/// and will affect the semantic of all index based operations. -pub async fn[R : Reader] BufferedReader::drop(self : Self[R], n : Int) -> Unit { - ignore(Reader::drop(self, n)) -} - -///| -pub impl[R : Reader] Reader for BufferedReader[R] with _get_internal_buffer( - self, -) { - self.0._get_internal_buffer() -} - -///| -pub impl[R : Reader] Reader for BufferedReader[R] with _direct_read( - self, - dst, - offset~, - max_len~, -) { - self.0._direct_read(dst, offset~, max_len~) -} - -///| -/// Get the nth byte from the start of the reader. -/// If there are no enough data available, -/// `BufferedReader` will request more data from the inner reader. -/// If the inner reader is closed before enough data is available, -/// `ReaderClosed` will be raised. -/// `op_get` will not advance the reader stream, -/// so this operation is idempotent. -pub async fn[R : Reader] BufferedReader::op_get( - self : Self[R], - index : Int, -) -> Byte { - self.ensure(index + 1) - let buf = self.0._get_internal_buffer() - buf.buf[buf.start + index] -} - -///| -/// Get a slice of data from the reader, -/// `start` and `end` count from start of stream. -/// If there are no enough data available, -/// `BufferedReader` will request more data from the inner reader. -/// If the inner reader is closed before enough data is available, -/// `ReaderClosed` will be raised. -/// -/// `op_as_view` will not advance the reader stream, -/// so this operation is idempotent. -/// -/// The returned bytes view MUST be temporary. -/// If data is consumed (for example via `.drop()` or `.read()`) -/// from the reader after `op_as_view`, the view MUST NOT be used again. -/// The view should be copied via `.to_bytes()` -/// before consuming data from the reader. -pub async fn[R : Reader] BufferedReader::op_as_view( - self : Self[R], - start? : Int = 0, - end~ : Int, -) -> BytesView { - if start == end { - return "" - } - guard start < end - self.ensure(end) - let buf = self.0._get_internal_buffer() - buf.buf.unsafe_reinterpret_as_bytes()[buf.start + start:buf.start + end] -} - -///| -/// Find the start index of the first occurence of `bytes` in the reader. -/// The returned index is counted from start of reader. -/// -/// If the target substring is not found in buffered data, -/// `BufferedReader` will request more data from the inner reader. -/// -/// If the inner reader is closed before the target substring is found, -/// `None` will be returned. -/// -/// `find_opt` will not advance the reader stream, -/// so this operation is idempotent. -pub async fn[R : Reader] BufferedReader::find_opt( - self : Self[R], - target : Bytes, -) -> Int? { - self.0._get_internal_buffer().find_opt(target, reader=self.0) -} - -///| -/// Find the start index of the first occurence of `bytes` in the reader. -/// The returned index is counted from start of reader. -/// -/// If the target substring is not found in buffered data, -/// `BufferedReader` will request more data from the inner reader. -/// -/// If the inner reader is closed before the target substring is found, -/// `ReaderClosed` will be raised. -/// -/// `find` will not advance the reader stream, -/// so this operation is idempotent. -pub async fn[R : Reader] BufferedReader::find( - self : Self[R], - target : Bytes, -) -> Int { - match self.find_opt(target) { - None => raise ReaderClosed - Some(index) => index - } -} - -///| -/// Read content from a buffered reader until newline (`\n`). -/// If the reader already reaches EOF, `None` is returned. -/// Otherwise, the content of the line (without the trailing newline) is returned, -/// and the content of the line and the newline character -/// will be conusmed from the reader. -/// The returned string is decoded with UTF8. -pub async fn[R : Reader] BufferedReader::read_line(self : Self[R]) -> String? { - self.read_until("\n") -} diff --git a/src/io/buffered_reader_wbtest.mbt b/src/io/buffered_reader_wbtest.mbt deleted file mode 100644 index e7cf86f9..00000000 --- a/src/io/buffered_reader_wbtest.mbt +++ /dev/null @@ -1,350 +0,0 @@ -// Copyright 2025 International Digital Economy Academy -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -///| -async fn writer(log : StringBuilder, w : PipeWrite) -> Unit { - defer w.close() - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"abcd") - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"efgh") - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"ijkl") -} - -///| -async test "BufferedReader::read" { - let log = StringBuilder::new() - @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => writer(log, w)) - defer r.close() - let reader = BufferedReader::new(r) - let buf = FixedArray::make(6, b'0') - while reader.read(buf) is n && n > 0 { - let data = buf.unsafe_reinterpret_as_bytes()[0:n] - let data = @utf8.decode(data) - log.write_string("received: \{data}\n") - } - log.write_string("buffered reader closed\n") - }) - inspect( - log.to_string(), - content=( - #|writing 4 bytes of data - #|received: abcd - #|writing 4 bytes of data - #|received: efgh - #|writing 4 bytes of data - #|received: ijkl - #|buffered reader closed - #| - ), - ) -} - -///| -async test "BufferedReader::read_exactly" { - let log = StringBuilder::new() - @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => writer(log, w)) - defer r.close() - let reader = BufferedReader::new(r) - for { - let data = reader.read_exactly(6) - let data = @utf8.decode(data) - log.write_string("received: \{data}\n") - } - }) catch { - err => log.write_object(err) - } - inspect( - log.to_string(), - content=( - #|writing 4 bytes of data - #|writing 4 bytes of data - #|received: abcdef - #|writing 4 bytes of data - #|received: ghijkl - #|ReaderClosed - ), - ) -} - -///| -async test "BufferedReader::op_get" { - let log = StringBuilder::new() - log.write_object( - try? @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => writer(log, w)) - defer r.close() - let reader = BufferedReader::new(r) - log.write_string("reader[5]: \{reader[5]}\n") - // should be idempotent - log.write_string("reader[5]: \{reader[5]}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - log.write_string("reader[5]: \{reader[5]}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - log.write_string("reader[5]: \{reader[5]}\n") - }), - ) - inspect( - log.to_string(), - content=( - #|writing 4 bytes of data - #|writing 4 bytes of data - #|reader[5]: b'\x66' - #|reader[5]: b'\x66' - #|reader.drop(4) - #|writing 4 bytes of data - #|reader[5]: b'\x6A' - #|reader.drop(4) - #|Err(ReaderClosed) - ), - ) -} - -///| -async test "BufferedReader::op_as_view" { - let log = StringBuilder::new() - log.write_object( - try? @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => writer(log, w)) - defer r.close() - let reader = BufferedReader::new(r) - let slice = @utf8.decode(reader[0:6]) - log.write_string("reader[0:6]: \{slice}\n") - // should be idempotent - let slice = @utf8.decode(reader[0:6]) - log.write_string("reader[0:6]: \{slice}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - let slice = @utf8.decode(reader[0:6]) - log.write_string("reader[0:6]: \{slice}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - let slice = @utf8.decode(reader[0:6]) - log.write_string("reader[0:6]: \{slice}\n") - }), - ) - inspect( - log.to_string(), - content=( - #|writing 4 bytes of data - #|writing 4 bytes of data - #|reader[0:6]: abcdef - #|reader[0:6]: abcdef - #|reader.drop(4) - #|writing 4 bytes of data - #|reader[0:6]: efghij - #|reader.drop(4) - #|Err(ReaderClosed) - ), - ) -} - -///| -async test "BufferedReader::find single byte" { - let log = StringBuilder::new() - log.write_object( - try? @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => { - defer w.close() - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"abcd") - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"efgh") - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"abcd") - }) - defer r.close() - let reader = BufferedReader::new(r) - let i = reader.find(b"a") - log.write_string("index of 'a': \{i}\n") - // should be idempotent - let i = reader.find(b"a") - log.write_string("index of 'a': \{i}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - let i = reader.find(b"a") - log.write_string("index of 'a': \{i}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - let i = reader.find(b"a") - log.write_string("index of 'a': \{i}\n") - let i = reader.find(b"x") - log.write_string("index of 'x': \{i}\n") - }), - ) - inspect( - log.to_string(), - content=( - #|writing 4 bytes of data - #|index of 'a': 0 - #|index of 'a': 0 - #|reader.drop(4) - #|writing 4 bytes of data - #|writing 4 bytes of data - #|index of 'a': 4 - #|reader.drop(4) - #|index of 'a': 0 - #|Err(ReaderClosed) - ), - ) -} - -///| -async test "BufferedReader::find bytes" { - let log = StringBuilder::new() - log.write_object( - try? @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => { - defer w.close() - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"abcd") - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"aBcd") - @async.sleep(20) - log.write_string("writing 4 bytes of data\n") - w.write(b"abcd") - }) - defer r.close() - let reader = BufferedReader::new(r) - let i = reader.find(b"ab") - log.write_string("index of \"ab\": \{i}\n") - let i = reader.find(b"aB") - log.write_string("index of \"aB\": \{i}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - let i = reader.find(b"ab") - log.write_string("index of \"ab\": \{i}\n") - log.write_string("reader.drop(4)\n") - reader.drop(4) - let i = reader.find(b"ab") - log.write_string("index of \"ab\": \{i}\n") - let i = reader.find(b"aB") - log.write_string("index of \"aB\": \{i}\n") - }), - ) - inspect( - log.to_string(), - content=( - #|writing 4 bytes of data - #|index of "ab": 0 - #|writing 4 bytes of data - #|index of "aB": 4 - #|reader.drop(4) - #|writing 4 bytes of data - #|index of "ab": 4 - #|reader.drop(4) - #|index of "ab": 0 - #|Err(ReaderClosed) - ), - ) -} - -///| -async test "BufferedReader::find_bytes splitted" { - @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => { - defer w.close() - w.write(b"abcd") - @async.sleep(100) - w.write(b"efgh") - }) - defer r.close() - let reader = BufferedReader::new(r) - inspect(reader.find_opt("cdef"), content="Some(2)") - }) -} - -///| -async test "BufferedReader::find_opt" { - @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => { - defer w.close() - @async.sleep(20) - w.write(b"abcd") - @async.sleep(20) - w.write(b"aBcd") - @async.sleep(20) - w.write(b"abcd") - }) - defer r.close() - let reader = BufferedReader::new(r) - inspect(reader.find_opt(b"ab"), content="Some(0)") - reader.drop(4) - inspect(reader.find_opt(b"ab"), content="Some(4)") - reader.drop(8) - inspect(reader.find_opt(b"ab"), content="None") - }) -} - -///| -async test "lazy drop" { - let log = StringBuilder::new() - @async.with_task_group(root => { - let (r, w) = pipe() - root.spawn_bg(() => { - defer w.close() - w.write("abcd") - @async.sleep(20) - w.write("efgh") - }) - defer r.close() - let reader = BufferedReader::new(r) - let _ = reader.read_exactly(2) - log.write_string(reader[:2] |> @bytes_util.ascii_to_string) - let _ = reader.read_exactly(4) - log.write_string(reader[:2] |> @bytes_util.ascii_to_string) - }) - inspect(log.to_string(), content="cdgh") -} - -///| -#cfg(target="native") -async test "BufferedReader::read_line" { - let file = @fs.open("LICENSE", mode=ReadOnly) - defer file.close() - let reader = BufferedReader::new(file) - let lines = [] - while reader.read_line() is Some(line) { - lines.push(line) - } - inspect(lines.length(), content="202") - assert_eq(lines.join("\n") + "\n", @fs.read_file("LICENSE").text()) -} - -///| -#cfg(not(target="native")) -fn _ignore_unused_import() -> Unit { - ignore(@fs.unimplemented) -} diff --git a/src/io/pkg.generated.mbti b/src/io/pkg.generated.mbti index 6acf26d3..aaeaf80a 100644 --- a/src/io/pkg.generated.mbti +++ b/src/io/pkg.generated.mbti @@ -14,17 +14,6 @@ pub impl Show for ReaderClosed pub impl ToJson for ReaderClosed // Types and methods -#deprecated -type BufferedReader[R] -pub async fn[R : Reader] BufferedReader::drop(Self[R], Int) -> Unit -pub async fn[R : Reader] BufferedReader::find(Self[R], Bytes) -> Int -pub async fn[R : Reader] BufferedReader::find_opt(Self[R], Bytes) -> Int? -pub fn[R] BufferedReader::new(R) -> Self[R] -pub async fn[R : Reader] BufferedReader::op_as_view(Self[R], start? : Int, end~ : Int) -> BytesView -pub async fn[R : Reader] BufferedReader::op_get(Self[R], Int) -> Byte -pub async fn[R : Reader] BufferedReader::read_line(Self[R]) -> String? -pub impl[R : Reader] Reader for BufferedReader[R] - type BufferedWriter[W] pub fn[W] BufferedWriter::capacity(Self[W]) -> Int pub async fn[W : Writer] BufferedWriter::flush(Self[W]) -> Unit @@ -74,7 +63,5 @@ pub(open) trait Writer { async write_once(Self, Bytes, offset~ : Int, len~ : Int) -> Int async write(Self, &Data) -> Unit = _ async write_reader(Self, &Reader) -> Unit = _ - #deprecated - async write_string(Self, StringView, encoding~ : Encoding) -> Unit = _ } diff --git a/src/io/writer.mbt b/src/io/writer.mbt index 02a3f972..fa6dad41 100644 --- a/src/io/writer.mbt +++ b/src/io/writer.mbt @@ -22,8 +22,6 @@ pub(open) trait Writer { async write_once(Self, Bytes, offset~ : Int, len~ : Int) -> Int async write(Self, &Data) -> Unit = _ async write_reader(Self, &Reader) -> Unit = _ - #deprecated("use `write` instead", skip_current_package=true) - async write_string(Self, StringView, encoding~ : Encoding) -> Unit = _ } ///| @@ -59,10 +57,3 @@ impl Writer with write_reader(self, reader) { self.write(buf_bytes[:n]) } } - -///| -impl Writer with write_string(self, str, encoding~) { - guard encoding is UTF8 - let data = @utf8.encode(str, bom=false) - self.write(data) -} diff --git a/src/pkg.generated.mbti b/src/pkg.generated.mbti index ae6b1ec7..ef16adc0 100644 --- a/src/pkg.generated.mbti +++ b/src/pkg.generated.mbti @@ -29,9 +29,6 @@ pub async fn[X] retry(RetryMethod, max_retry? : Int, fatal_error? : (Error) -> B pub async fn sleep(Int) -> Unit -#deprecated -pub fn with_event_loop(async (TaskGroup[Unit]) -> Unit) -> Unit raise - pub async fn[X] with_task_group(async (TaskGroup[X]) -> X) -> X pub async fn[X] with_timeout(Int, async () -> X, error? : Error) -> X @@ -39,10 +36,6 @@ pub async fn[X] with_timeout(Int, async () -> X, error? : Error) -> X pub async fn[X] with_timeout_opt(Int, async () -> X) -> X? // Errors -#deprecated -pub suberror AlreadyTerminated -pub impl Show for AlreadyTerminated - pub suberror TimeoutError pub impl Show for TimeoutError pub impl ToJson for TimeoutError diff --git a/src/socket/pkg.generated.mbti b/src/socket/pkg.generated.mbti index 6d2d180a..58ae06be 100644 --- a/src/socket/pkg.generated.mbti +++ b/src/socket/pkg.generated.mbti @@ -40,7 +40,6 @@ pub(all) enum IpProtocolPreference { } pub impl Show for IpProtocolPreference -#alias(TCP, deprecated) type Tcp pub fn Tcp::addr(Self) -> Addr pub fn Tcp::close(Self) -> Unit @@ -50,7 +49,6 @@ pub fn Tcp::enable_keepalive(Self, idle_before_keep_alive? : Int, keep_alive_cou pub impl @io.Reader for Tcp pub impl @io.Writer for Tcp -#alias(TCPServer, deprecated) type TcpServer pub async fn TcpServer::accept(Self) -> (Tcp, Addr) pub fn TcpServer::addr(Self) -> Addr diff --git a/src/socket/tcp.mbt b/src/socket/tcp.mbt index 64470765..9b2cc537 100644 --- a/src/socket/tcp.mbt +++ b/src/socket/tcp.mbt @@ -14,7 +14,6 @@ ///| /// A Tcp connection -#alias(TCP, deprecated="use `Tcp` instead") struct Tcp { io : @event_loop.IoHandle family : AddrFamily @@ -27,7 +26,6 @@ pub fn Tcp::close(self : Tcp) -> Unit { } ///| -#alias(TCPServer, deprecated="use `TcpServer` instead") struct TcpServer { io : @event_loop.IoHandle family : AddrFamily diff --git a/src/task_group.mbt b/src/task_group.mbt index 0b5c4a05..b3085b28 100644 --- a/src/task_group.mbt +++ b/src/task_group.mbt @@ -40,10 +40,6 @@ struct TaskGroup[X] { group_defer : Array[async () -> Unit] } -///| -#deprecated("this error is no longer emitted") -pub suberror AlreadyTerminated derive(Show) - ///| fn[X] TaskGroup::spawn_coroutine( self : TaskGroup[X], diff --git a/src/tls/openssl.mbt b/src/tls/openssl.mbt index 54da696c..b0ccd770 100644 --- a/src/tls/openssl.mbt +++ b/src/tls/openssl.mbt @@ -245,7 +245,6 @@ fn BIO::write(bio : BIO, src : @c_buffer.Buffer, len : Int) -> Int { ///| /// A TLS-encrypted connection #cfg(not(platform="windows")) -#alias(TLS, deprecated="use `Tls` instead") struct Tls { ssl : SSL host : String? diff --git a/src/tls/pkg.generated.mbti b/src/tls/pkg.generated.mbti index c56ca669..123c08da 100644 --- a/src/tls/pkg.generated.mbti +++ b/src/tls/pkg.generated.mbti @@ -22,7 +22,6 @@ pub impl Show for TlsError pub impl ToJson for TlsError // Types and methods -#alias(TLS, deprecated) type Tls pub async fn[Inner : @io.Reader + @io.Writer] Tls::client(Inner, verify? : Bool, host? : String, sni? : Bool) -> Self pub async fn[R : @io.Reader, W : @io.Writer] Tls::client_from_pair(R, W, verify? : Bool, host? : String, sni? : Bool) -> Self