pub struct SRTFile {
pub lines: Vec<SRTLine>,
}
Expand description
Contains a Vec<SRTLine>
The .srt
format is relatively simple to parse and generally looks like :
0
00:00:00,000 --> 00:00:02,000
This is my text
1
00:00:02,000 --> 00:00:04,000
This is my second text
The parse function takes as input a String that represents either the parsed file or the path to it.
A simple example of working with this would be the following :
use rsubs_lib::srt::parse;
let mut a = parse("./tests/fixtures/test.srt".to_string()).unwrap();
for line in a.lines.iter_mut(){
line.line_text.push_str(" Ipsum"); // add "Ipsum" to the end of each line.
}
// print the parsed and modified `.srt` file
println!("{}",a.clone());
// and then write it to a file
a.to_file("./tests/fixtures/doctest1.srt");
Fields§
§lines: Vec<SRTLine>
Implementations§
source§impl SRTFile
impl SRTFile
sourcepub fn to_file(self, path: &str) -> Result<()>
pub fn to_file(self, path: &str) -> Result<()>
Takes the path of the file in the form of a String to be written to as input.
Examples found in repository?
examples/convert_around.rs (line 17)
7 8 9 10 11 12 13 14 15 16 17 18 19
fn main() {
vtt::VTTFile::from(srt::SRTFile::from_str("./tests/fixtures/test.srt").unwrap()) // Can read either a file or a string
// converts file to WEBVTT
.to_file("./tests/fixtures/ex_test_1.vtt") // Writes the converted subtitle to a file
.unwrap();
ssa::SSAFile::from(vtt::parse("./tests/fixtures/test.vtt".to_string()).unwrap()) // converts file to SSA/ASS
.to_file("./tests/fixtures/ex_test_1.ass")
.unwrap();
srt::SRTFile::from(ssa::parse("./tests/fixtures/test.ass".to_string()).unwrap())
// converts file to SRT
.to_file("./tests/fixtures/ex_test_1.srt")
.unwrap();
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for SRTFile
impl<'de> Deserialize<'de> for SRTFile
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq for SRTFile
impl PartialEq for SRTFile
impl Eq for SRTFile
impl StructuralEq for SRTFile
impl StructuralPartialEq for SRTFile
Auto Trait Implementations§
impl RefUnwindSafe for SRTFile
impl Send for SRTFile
impl Sync for SRTFile
impl Unpin for SRTFile
impl UnwindSafe for SRTFile
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