libutils_console/
descriptor.rs1use libutils_issue::{
7 Issue,
8 Severity
9};
10
11use alloc::{
13 string::{
14 String,
15 ToString
16 },
17 vec::Vec
18};
19
20use super::metadata::Metadata;
22
23
24#[must_use]
30pub trait Descriptor: Sized {
31 fn metadata(&self) -> Result<impl Metadata, Issue>;
32 fn read_bytes(&mut self) -> Result<Vec<u8>, Issue>;
33 fn read(&mut self) -> Result<String, Issue> {return String::from_utf8(self.read_bytes()?).map_err(|error| Issue {
34 name: "Error encoding file to UTF-8",
35 description: Some(error.to_string()),
36 severity: Severity::Error
37 })}
38 fn write_bytes(&mut self, content: &[u8]) -> Result<(), Issue>;
39 fn write(&mut self, content: &str) -> Result<(), Issue> {return self.write_bytes(content.as_bytes())}
40 fn close(self) -> () {}
41}