use interior mutability for SourceFile lines
Using shared ownership for these may or may not have been a mistake in the first place. We'll find out.
This commit is contained in:
parent
e5d0bdf0c0
commit
34a9c3f864
3 changed files with 136 additions and 15 deletions
21
src/lib.rs
21
src/lib.rs
|
|
@ -1,4 +1,4 @@
|
|||
use std::{io::BufWriter, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) mod prelude {
|
||||
#![allow(unused_imports)]
|
||||
|
|
@ -7,7 +7,7 @@ pub(crate) mod prelude {
|
|||
error::Error as StdError,
|
||||
ffi::{OsStr, OsString},
|
||||
fmt::{Display, Formatter, Result as FmtResult},
|
||||
io::{Error as IoError, Read, Seek, SeekFrom},
|
||||
io::{Error as IoError, Read, Seek, SeekFrom, Write},
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, ExitCode},
|
||||
str::FromStr,
|
||||
|
|
@ -85,7 +85,6 @@ pub fn get_highest_prio(
|
|||
OsStr::new("; }"),
|
||||
]
|
||||
.into_iter()
|
||||
.map(ToOwned::to_owned)
|
||||
.collect();
|
||||
|
||||
// Get the highest priority, and the file its defined in.
|
||||
|
|
@ -118,11 +117,21 @@ pub fn get_highest_prio(
|
|||
pub fn write_next_prio(
|
||||
mut source: SourceFile,
|
||||
last_line_def: SourceLine,
|
||||
new_prio: u64,
|
||||
last_pri: i64,
|
||||
new_prio: i64,
|
||||
) -> Result<(), BoxDynError> {
|
||||
let lines = source.lines()?;
|
||||
//let lines = source.lines()?;
|
||||
|
||||
for line in lines {}
|
||||
let old_text = last_line_def.text();
|
||||
let new_text = old_text.replace(last_pri.to_string().as_str(), new_prio.to_string().as_str());
|
||||
|
||||
let new_line = SourceLine {
|
||||
line: Line::from_index(last_line_def.line.index() + 1),
|
||||
path: source.path(),
|
||||
text: Arc::from(new_text),
|
||||
};
|
||||
|
||||
source.insert_line(new_line.line, new_line.text())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue