mirror of https://github.com/helix-editor/helix
remove unsafe
parent
cec5d437d8
commit
fa4caf7e3d
|
@ -125,7 +125,7 @@ impl ChangeSet {
|
||||||
/// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
|
/// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
|
||||||
/// returned value will represent the change `docA` → `docC`.
|
/// returned value will represent the change `docA` → `docC`.
|
||||||
pub fn compose(self, other: Self) -> Self {
|
pub fn compose(self, other: Self) -> Self {
|
||||||
debug_assert!(self.len_after == other.len);
|
assert!(self.len_after == other.len);
|
||||||
|
|
||||||
// composing fails in weird ways if one of the sets is empty
|
// composing fails in weird ways if one of the sets is empty
|
||||||
// a: [] len: 0 len_after: 1 | b: [Insert(Tendril<UTF8>(inline: "\n")), Retain(1)] len 1
|
// a: [] len: 0 len_after: 1 | b: [Insert(Tendril<UTF8>(inline: "\n")), Retain(1)] len 1
|
||||||
|
|
|
@ -102,7 +102,7 @@ pub struct Document {
|
||||||
language_server: Option<Arc<helix_lsp::Client>>,
|
language_server: Option<Arc<helix_lsp::Client>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::fmt;
|
use std::{fmt, mem};
|
||||||
impl fmt::Debug for Document {
|
impl fmt::Debug for Document {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("Document")
|
f.debug_struct("Document")
|
||||||
|
@ -301,20 +301,13 @@ pub async fn to_writer<'a, W: tokio::io::AsyncWriteExt + Unpin + ?Sized>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like std::mem::replace() except it allows the replacement value to be mapped from the
|
fn take_with<T, F>(mut_ref: &mut T, f: F)
|
||||||
/// original value.
|
|
||||||
fn take_with<T, F>(mut_ref: &mut T, closure: F)
|
|
||||||
where
|
where
|
||||||
|
T: Default,
|
||||||
F: FnOnce(T) -> T,
|
F: FnOnce(T) -> T,
|
||||||
{
|
{
|
||||||
use std::{panic, ptr};
|
let t = mem::take(mut_ref);
|
||||||
|
let _ = mem::replace(mut_ref, f(t));
|
||||||
unsafe {
|
|
||||||
let old_t = ptr::read(mut_ref);
|
|
||||||
let new_t = panic::catch_unwind(panic::AssertUnwindSafe(|| closure(old_t)))
|
|
||||||
.unwrap_or_else(|_| ::std::process::abort());
|
|
||||||
ptr::write(mut_ref, new_t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use helix_lsp::lsp;
|
use helix_lsp::lsp;
|
||||||
|
|
Loading…
Reference in New Issue