INNER CODE UNIT · Rust

from_str

szabodanika/microbin · src/args.rs:269

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        if let Some(path) = s.strip_prefix("file://").or_else(|| s.strip_prefix("file:")) {
            // Read value from file
            fs::read_to_string(path)
                .map(|content| SecretArg(content.trim().to_string()))
                .map_err(|e| format!("Failed to read secret from {}: {}", path, e))
        } else {
            // Use the raw string provided
            Ok(SecretArg(s.to_string()))
        }
    }
}

// Allow it to be treated like a string automatically
impl std::ops::Deref for SecretArg {
    type Target = String;
    fn deref(&self) -> &Self::Target {
        &self.0

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…