pub struct Sbatch { /* private fields */ }
Expand description
sbatch command builder
§Examples
use sbatch_rs::{Sbatch, SbatchOption};
// Create a new `Sbatch` instance
let sbatch = Sbatch::new()
.add_option(SbatchOption::JobName("test".to_string())).unwrap()
.add_option(SbatchOption::Output("test.out".to_string())).unwrap()
.add_option(SbatchOption::Error("test.err".to_string())).unwrap()
.set_script("test.sh".to_string()).unwrap()
.build();
// Verify that the `sbatch` command was built properly
assert!(sbatch.is_ok());
assert_eq!(sbatch.unwrap(), "sbatch --error=test.err --job-name=test --output=test.out test.sh");
Implementations§
Source§impl Sbatch
impl Sbatch
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Sbatch
instance.
§Examples
use sbatch_rs::Sbatch;
// Create a new `Sbatch` instance
let sbatch = Sbatch::new();
Sourcepub fn add_option(
&mut self,
option: SbatchOption,
) -> Result<&mut Self, SbatchError>
pub fn add_option( &mut self, option: SbatchOption, ) -> Result<&mut Self, SbatchError>
Adds an SbatchOption
to the Sbatch
instance.
§Arguments
option
- AnSbatchOption
to add to theSbatch
instance.
§Returns
This function returns a mutable reference to the Sbatch
instance.
§Errors
This function returns a SbatchError
if the SbatchOption
is invalid.
§Examples
use sbatch_rs::{Sbatch, SbatchOption};
// Create a new `Sbatch` instance
let sbatch = Sbatch::new()
.add_option(SbatchOption::JobName("test".to_string())).unwrap()
.add_option(SbatchOption::Output("test.out".to_string())).unwrap()
.add_option(SbatchOption::Error("test.err".to_string())).unwrap()
.add_option(SbatchOption::Wrap("test".to_string())).unwrap()
.build();
// Verify that the `sbatch` command was built properly
assert!(sbatch.is_ok());
assert_eq!(sbatch.unwrap(), "sbatch --error=test.err --job-name=test --output=test.out --wrap=\"test\"");
Sourcepub fn set_script(&mut self, script: String) -> Result<&mut Self, SbatchError>
pub fn set_script(&mut self, script: String) -> Result<&mut Self, SbatchError>
Sets the script for the Sbatch
instance.
§Arguments
script
- A string representing the script to run.
§Returns
This function returns a mutable reference to the Sbatch
instance.
§Errors
This function returns a SbatchError
if the script is empty.
§Examples
use sbatch_rs::Sbatch;
// Create a new `Sbatch` instance
let sbatch = Sbatch::new()
.set_script("test.sh".to_string()).unwrap()
.build();
// Verify that the `sbatch` command was built properly
assert!(sbatch.is_ok());
assert_eq!(sbatch.unwrap(), "sbatch test.sh");
Sourcepub fn build(&self) -> Result<String, SbatchError>
pub fn build(&self) -> Result<String, SbatchError>
Builds the sbatch
command.
§Returns
This function returns a string representing the sbatch
command.
§Errors
This function returns a SbatchError
if no options or script are provided.
§Examples
use sbatch_rs::{Sbatch, SbatchOption};
// Create a new `Sbatch` instance
let sbatch = Sbatch::new()
.add_option(SbatchOption::JobName("test".to_string())).unwrap()
.add_option(SbatchOption::Output("test.out".to_string())).unwrap()
.add_option(SbatchOption::Error("test.err".to_string())).unwrap()
.set_script("test.sh".to_string()).unwrap()
.build();
// Verify that the `sbatch` command was built properly
assert!(sbatch.is_ok());
assert_eq!(sbatch.unwrap(), "sbatch --error=test.err --job-name=test --output=test.out test.sh");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sbatch
impl RefUnwindSafe for Sbatch
impl Send for Sbatch
impl Sync for Sbatch
impl Unpin for Sbatch
impl UnwindSafe for Sbatch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more