Skip to content

Commit

Permalink
from_str for Pep732Metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
blueraft committed Aug 10, 2024
1 parent 1f89782 commit 1aa15eb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/uv-scripts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeMap;
use std::io;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::LazyLock;

use memchr::memmem::Finder;
Expand Down Expand Up @@ -39,7 +40,7 @@ impl Pep723Script {
};

// Parse the metadata.
let metadata = Pep723Metadata::from_string(metadata)?;
let metadata = Pep723Metadata::from_str(&metadata)?;

Ok(Some(Self {
path: file.as_ref().to_path_buf(),
Expand Down Expand Up @@ -72,11 +73,15 @@ pub struct Pep723Metadata {
pub raw: String,
}

impl Pep723Metadata {
impl FromStr for Pep723Metadata {
type Err = Pep723Error;
/// Parse `Pep723Metadata` from a raw TOML string.
pub fn from_string(raw: String) -> Result<Self, toml::de::Error> {
let metadata = toml::from_str(&raw)?;
Ok(Pep723Metadata { raw, ..metadata })
fn from_str(raw: &str) -> Result<Self, Self::Err> {
let metadata = toml::from_str(raw)?;
Ok(Pep723Metadata {
raw: raw.to_string(),
..metadata
})
}
}

Expand Down

0 comments on commit 1aa15eb

Please sign in to comment.