mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2025-04-25 07:22:15 +00:00
Merge pull request #20 from fluencelabs/mb_stringify
This commit is contained in:
commit
bb8511f4dc
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fluence"
|
||||
version = "0.3.1" # remember to update html_root_url
|
||||
version = "0.3.3" # remember to update html_root_url
|
||||
description = "Fluence backend SDK for developing backend applications for the Fluence network"
|
||||
documentation = "https://docs.rs/fluence/"
|
||||
repository = "https://github.com/fluencelabs/rust-sdk"
|
||||
@ -18,8 +18,8 @@ all-features = true
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-macro = { path = "crates/macro", version = "=0.3.1" }
|
||||
fluence-sdk-main = { path = "crates/main", version = "=0.3.1" }
|
||||
fluence-sdk-macro = { path = "crates/macro", version = "=0.3.3" }
|
||||
fluence-sdk-main = { path = "crates/main", version = "=0.3.3" }
|
||||
|
||||
[features]
|
||||
# Print some internal logs by log_utf8_string
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fluence-sdk-macro"
|
||||
version = "0.3.1" # remember to update html_root_url
|
||||
version = "0.3.3" # remember to update html_root_url
|
||||
edition = "2018"
|
||||
description = "Definition of `#[invoke_handler]` attribute"
|
||||
documentation = "https://docs.rs/fluence/fluence-sdk-macro"
|
||||
@ -17,4 +17,4 @@ all-features = true
|
||||
proc-macro = true
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-wit = { path = "../wit", version = "=0.3.1" }
|
||||
fluence-sdk-wit = { path = "../wit", version = "=0.3.3" }
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fluence-sdk-main"
|
||||
version = "0.3.1" # remember to update html_root_url
|
||||
version = "0.3.3" # remember to update html_root_url
|
||||
edition = "2018"
|
||||
description = "Rust SDK for applications for the Fluence network"
|
||||
documentation = "https://docs.rs/fluence/fluence-sdk-macro"
|
||||
@ -18,7 +18,7 @@ path = "src/lib.rs"
|
||||
crate-type = ["rlib"]
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-macro = { path = "../macro", version = "=0.3.1" }
|
||||
fluence-sdk-macro = { path = "../macro", version = "=0.3.3" }
|
||||
|
||||
log = { version = "0.4.8", features = ["std"] }
|
||||
serde = "=1.0.118"
|
||||
|
@ -38,6 +38,23 @@ pub struct Result {
|
||||
pub stderr: Vec<u8>,
|
||||
}
|
||||
|
||||
/// The same as the Result, but stdout and stderr are utf8 strings.
|
||||
#[fce]
|
||||
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
|
||||
pub struct StringResult {
|
||||
/// Return process exit code or host execution error code, where SUCCESS_CODE means success.
|
||||
pub ret_code: i32,
|
||||
|
||||
/// Contains the string representation of an error, if ret_code != SUCCESS_CODE.
|
||||
pub error: String,
|
||||
|
||||
/// The data that the process wrote to stdout.
|
||||
pub stdout: String,
|
||||
|
||||
/// The data that the process wrote to stderr.
|
||||
pub stderr: String,
|
||||
}
|
||||
|
||||
impl Result {
|
||||
/// Create a new failure MountedBinaryResult from the provided ret_code.
|
||||
pub fn from_error(ret_code: i32, error: impl Into<String>) -> Self {
|
||||
@ -63,7 +80,7 @@ impl Result {
|
||||
let stdout = String::from_utf8(self.stdout).ok()?;
|
||||
Some(Ok(stdout))
|
||||
} else {
|
||||
let stderr = std::str::from_utf8(&self.stdout).ok()?;
|
||||
let stderr = std::str::from_utf8(&self.stderr).ok()?;
|
||||
Some(Ok(format!("error: {}, stderr: {}", self.error, stderr)))
|
||||
}
|
||||
}
|
||||
@ -77,8 +94,22 @@ impl Result {
|
||||
let stdout = String::from_utf8(self.stdout.clone()).ok()?;
|
||||
Some(Ok(stdout))
|
||||
} else {
|
||||
let stderr = std::str::from_utf8(&self.stdout).ok()?;
|
||||
let stderr = std::str::from_utf8(&self.stderr).ok()?;
|
||||
Some(Ok(format!("error: {}, stderr: {}", self.error, stderr)))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stringify(&self) -> Option<StringResult> {
|
||||
let stdout = String::from_utf8(self.stdout.clone()).ok()?;
|
||||
let stderr = String::from_utf8(self.stderr.clone()).ok()?;
|
||||
|
||||
let string_result = StringResult {
|
||||
ret_code: self.ret_code,
|
||||
error: self.error.clone(),
|
||||
stdout,
|
||||
stderr,
|
||||
};
|
||||
|
||||
Some(string_result)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "fluence-sdk-wit"
|
||||
version = "0.3.1" # remember to update html_root_url
|
||||
version = "0.3.3" # remember to update html_root_url
|
||||
edition = "2018"
|
||||
description = "Webassembly interface-types generator"
|
||||
documentation = "https://docs.rs/fluence/fluence-sdk-macro"
|
||||
|
@ -80,6 +80,7 @@ pub use fluence_sdk_main::WasmLoggerBuilder;
|
||||
pub use fluence_sdk_main::TargetMap;
|
||||
|
||||
pub use fluence_sdk_main::mounted_binary::Result as MountedBinaryResult;
|
||||
pub use fluence_sdk_main::mounted_binary::StringResult as MountedBinaryStringResult;
|
||||
pub use fluence_sdk_main::mounted_binary::SUCCESS_CODE as BINARY_SUCCESS_CODE;
|
||||
|
||||
/// These API functions are intended for internal usage in generated code.
|
||||
|
Loading…
x
Reference in New Issue
Block a user