Skip to content

Commit e79747c

Browse files
committed
deprecate some API that are no longer needed
1 parent 41208f9 commit e79747c

File tree

10 files changed

+17
-17
lines changed

10 files changed

+17
-17
lines changed

examples/http_file_server/main.mbt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,16 @@ async fn serve_directory(
2323
conn
2424
..send_response(200, "OK", extra_headers={ "Content-Type": "text/html" })
2525
..write("<!DOCTYPE html><html><head></head><body>")
26-
..write_string("<h1>\{path}</h1>\n", encoding=UTF8)
26+
..write("<h1>\{path}</h1>\n")
2727
..write("<div style=\"margin: 1em; font-size: 15pt\">")
28-
..write_string(
29-
"<a href=\"\{path}?download_zip\">download as zip</a><br/><br/>\n",
30-
encoding=UTF8,
31-
)
28+
..write("<a href=\"\{path}?download_zip\">download as zip</a><br/><br/>\n")
3229
if path[:-1].rev_find("/") is Some(index) {
3330
let parent : StringView = if index == 0 { "/" } else { path[:index] }
34-
conn.write_string("<a href=\"\{parent}\">..</a><br/><br/>\n", encoding=UTF8)
31+
conn.write("<a href=\"\{parent}\">..</a><br/><br/>\n")
3532
}
3633
for file in files {
3734
let sep = if path[path.length() - 1] != '/' { "/" } else { "" }
38-
conn.write_string(
39-
"<a href=\"\{path}\{sep}\{file}\">\{file}</a><br/>\n",
40-
encoding=UTF8,
41-
)
35+
conn.write("<a href=\"\{path}\{sep}\{file}\">\{file}</a><br/>\n")
4236
}
4337
conn..write("</div></body></html>")..end_response()
4438
}

examples/tcp_ping_pong/main.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async fn server(println : Printer) -> Unit {
3838
let msg = buf.unsafe_reinterpret_as_bytes()[0:n]
3939
println("server received: \{@encoding/utf8.decode(msg)}")
4040
let reply = "pong"
41-
conn.write_string(reply, encoding=UTF8)
41+
conn.write(reply)
4242
println("server sent: \{reply}")
4343
if msg == b"exit" {
4444
println("server initiate terminate")
@@ -68,7 +68,7 @@ async fn client(println : Printer, id : Int, msg : String) -> Unit {
6868
// with server side "received connection" message
6969
@async.sleep(10)
7070
println("client \{id}: connection established")
71-
conn.write_string(msg, encoding=UTF8)
71+
conn.write(msg)
7272
println("client \{id} sent: \{msg}")
7373
let buf = FixedArray::make(1024, b'0')
7474
if conn.read(buf) is n && n > 0 {

src/fs/fs.mbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ pub async fn read_file(path : String) -> &@io.Data {
290290

291291
///|
292292
/// Read the contents of a text file located at `path`.
293+
#deprecated("use `read_file(path).text()` instead")
293294
pub async fn read_text_file(path : String, encoding~ : @io.Encoding) -> String {
294295
guard encoding is UTF8
295296
read_file(path).text()
@@ -316,6 +317,7 @@ pub async fn write_file(
316317
/// Write data to a text file located at `path`.
317318
/// The meaning of `sync`, `append`, `create`, truncate` is the same as `open`,
318319
/// except that `truncate` is `true` by default. See `open` for more details.
320+
#deprecated("use `write_file(path, content)` instead")
319321
pub async fn write_text_file(
320322
path : String,
321323
content : String,

src/fs/pkg.generated.mbti

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ fn opendir(String) -> Directory raise
2626

2727
async fn read_file(String) -> &@io.Data
2828

29+
#deprecated
2930
async fn read_text_file(String, encoding~ : @io.Encoding) -> String
3031

3132
async fn readdir(String, include_hidden? : Bool, include_special? : Bool, sort? : Bool) -> Array[String]
@@ -38,6 +39,7 @@ async fn rmdir(String, recursive? : Bool) -> Unit
3839

3940
async fn write_file(String, Bytes, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> Unit
4041

42+
#deprecated
4143
async fn write_text_file(String, String, encoding~ : @io.Encoding, sync? : SyncMode, append? : Bool, create? : Int, truncate? : Bool) -> Unit
4244

4345
// Errors

src/fs/text_file_test.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async test "text file" {
1717
@async.with_task_group(fn(root) {
1818
let path = "basic_text_file_test"
1919
root.add_defer(() => @fs.remove(path))
20-
@fs.write_text_file(path, "abcd", encoding=UTF8, create=0o644)
21-
inspect(@fs.read_text_file(path, encoding=UTF8), content="abcd")
20+
@fs.write_file(path, "abcd", create=0o644)
21+
inspect(@fs.read_file(path).text(), content="abcd")
2222
})
2323
}

src/http/README.mbt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub async fn server(listen_addr : @socket.Addr) -> Unit {
8282
conn.skip_request_body()
8383
conn
8484
..send_response(404, "NotFound")
85-
..write_string("`\{request.path}` not found", encoding=UTF8)
85+
..write("`\{request.path}` not found")
8686
..end_response()
8787
}
8888
})

src/io/pkg.generated.mbti

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ pub(open) trait Writer {
5050
async write_once(Self, Bytes, offset~ : Int, len~ : Int) -> Int
5151
async write(Self, &Data) -> Unit = _
5252
async write_reader(Self, &Reader) -> Unit = _
53+
#deprecated
5354
async write_string(Self, StringView, encoding~ : Encoding) -> Unit = _
5455
}
5556

src/io/writer.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub(open) trait Writer {
2222
async write_once(Self, Bytes, offset~ : Int, len~ : Int) -> Int
2323
async write(Self, &Data) -> Unit = _
2424
async write_reader(Self, &Reader) -> Unit = _
25+
#deprecated("use `write` instead")
2526
async write_string(Self, StringView, encoding~ : Encoding) -> Unit = _
2627
}
2728

src/io/writer_test.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async test "write_string" {
113113
defer r.close()
114114
root.spawn_bg(fn() {
115115
defer w.close()
116-
w.write_string("abcd中文☺", encoding=UTF8)
116+
w.write("abcd中文☺")
117117
})
118118
inspect(r.read_all().text(), content="abcd中文☺")
119119
})

src/missing_close_test.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async test "missing_close" {
2424
})
2525
root.spawn_bg(fn() {
2626
let data = "abcd"
27-
w.write_string(data, encoding=UTF8)
27+
w.write(data)
2828
log.write_string("written \{data}\n")
2929
})
3030
})

0 commit comments

Comments
 (0)