Skip to content

Commit

Permalink
refactor(toml): Expose ScriptSource for reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Nov 25, 2024
1 parent 51cb5cc commit b4a8940
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/cargo/util/toml/embedded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ fn sanitize_name(name: &str) -> String {
}

#[derive(Debug)]
struct ScriptSource<'s> {
pub struct ScriptSource<'s> {
shebang: Option<&'s str>,
info: Option<&'s str>,
frontmatter: Option<&'s str>,
content: &'s str,
}

impl<'s> ScriptSource<'s> {
fn parse(input: &'s str) -> CargoResult<Self> {
pub fn parse(input: &'s str) -> CargoResult<Self> {
let mut source = Self {
shebang: None,
info: None,
Expand Down Expand Up @@ -280,19 +280,19 @@ impl<'s> ScriptSource<'s> {
Ok(source)
}

fn shebang(&self) -> Option<&'s str> {
pub fn shebang(&self) -> Option<&'s str> {
self.shebang
}

fn info(&self) -> Option<&'s str> {
pub fn info(&self) -> Option<&'s str> {
self.info
}

fn frontmatter(&self) -> Option<&'s str> {
pub fn frontmatter(&self) -> Option<&'s str> {
self.frontmatter
}

fn content(&self) -> &'s str {
pub fn content(&self) -> &'s str {
self.content
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ mod targets;

use self::targets::to_targets;

pub use embedded::ScriptSource;

/// See also `bin/cargo/commands/run.rs`s `is_manifest_command`
pub fn is_embedded(path: &Path) -> bool {
let ext = path.extension();
Expand Down

0 comments on commit b4a8940

Please sign in to comment.