Skip to main content

libutils_console/
continuations.rs

1//^
2//^ HEAD
3//^
4
5//> HEAD -> ALLOC
6use alloc::{
7    string::{
8        String, 
9        ToString
10    }, 
11    vec::Vec
12};
13
14//> HEAD -> ISSUE
15use libutils_issue::{
16    Issue,
17    Severity
18};
19
20
21//^
22//^ CONTINUATIONS
23//^
24
25//> CONTINUATIONS -> TRAIT
26#[must_use]
27pub trait Synchronization: Sized {
28    fn sync(self) -> ();
29    fn ignore(self) -> () {}
30}
31
32//> CONTINUATIONS -> DESCRIPTOR
33#[must_use]
34pub trait Descriptor: Sized {
35    fn read_bytes(&mut self) -> Result<Vec<u8>, Issue>;
36    fn read(&mut self) -> Result<String, Issue> {return String::from_utf8(self.read_bytes()?).map_err(|error| Issue {
37        name: "Error encoding file to UTF-8",
38        description: Some(error.to_string()),
39        severity: Severity::Error
40    })}
41    fn write_bytes(&mut self, content: &[u8]) -> Result<(), Issue>;
42    fn write(&mut self, content: &str) -> Result<(), Issue> {return self.write_bytes(content.as_bytes())}
43    fn close(self) -> () {}
44}