mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-26 10:47:11 -06:00
lint: method references and elided const lifetimes (S1612, S8863) (#4204)
Use function paths where a closure only forwarded its argument (PoisonError::into_inner, OsStr::to_str, FindRange::is_empty), and drop redundant 'static on associated and module consts. No behaviour change.
This commit is contained in:
@@ -179,7 +179,7 @@ impl<'a> Collector<'a> {
|
||||
/// Warns when a file that placed `.ai` file `source` links (`name`) was copied as `copy`: the
|
||||
/// copy of `source` finds it only by its name, beside it.
|
||||
fn renamed(&mut self, lines: &mut Vec<String>, source: &str, path: &str, name: &str, copy: &str) {
|
||||
if Path::new(copy).file_name().and_then(|n| n.to_str()) != Some(name) {
|
||||
if Path::new(copy).file_name().and_then(std::ffi::OsStr::to_str) != Some(name) {
|
||||
let message = format!(
|
||||
"{path}: copied as {copy}; the copy of {source} looks for it as {name} and shows the file of that name, if any, else its preview"
|
||||
);
|
||||
|
||||
@@ -603,7 +603,7 @@ struct Names {
|
||||
/// The name of the entry holding `bytes`: from their content (128 bits of hash and the length), so
|
||||
/// identical images share one entry and one written before isn't written again.
|
||||
fn blob_name(bytes: &Arc<Vec<u8>>) -> String {
|
||||
let mut guard = NAMES.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut guard = NAMES.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let Names { by_address, live_after_sweep } = &mut *guard;
|
||||
let names = by_address.get_or_insert_with(Default::default);
|
||||
let address = Arc::as_ptr(bytes) as usize;
|
||||
|
||||
@@ -127,7 +127,7 @@ impl SymbolLibrary {
|
||||
}
|
||||
|
||||
impl LibraryFile for SymbolLibrary {
|
||||
const EXTS: &'static [&'static str] = &[SYMBOLS_EXT];
|
||||
const EXTS: &[&str] = &[SYMBOLS_EXT];
|
||||
fn read(bytes: &[u8], stem: &str) -> std::result::Result<Self, String> {
|
||||
let doc = vectorcraft_format::load(bytes).map_err(|e| e.to_string())?;
|
||||
SymbolLibrary::from_document(&doc, &[], stem.to_string())
|
||||
|
||||
@@ -347,7 +347,7 @@ impl FindFilter {
|
||||
[self.name.as_ref(), self.kind.as_ref(), self.text.as_ref()].iter().all(|f| f.is_none())
|
||||
&& self.within.is_none()
|
||||
&& self.intersects.is_none()
|
||||
&& self.ranges().iter().all(|r| r.is_empty())
|
||||
&& self.ranges().iter().all(FindRange::is_empty)
|
||||
&& self.anchors.is_empty()
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn files(dir: &Path, out: &mut Vec<PathBuf>) {
|
||||
files(&p, out);
|
||||
} else if p
|
||||
.extension()
|
||||
.and_then(|x| x.to_str())
|
||||
.and_then(std::ffi::OsStr::to_str)
|
||||
.is_some_and(|x| ["af", "afdesign", "afpub", "afphoto"].contains(&x.to_ascii_lowercase().as_str()))
|
||||
{
|
||||
out.push(p);
|
||||
|
||||
@@ -155,7 +155,7 @@ pub fn apply(id: &str, params: &Value, path: &PathData, bounds: Rect, rule: Fill
|
||||
path: path.clone(),
|
||||
};
|
||||
let h = key.hash64();
|
||||
if let Some((k, out)) = CACHE.lock().unwrap_or_else(|e| e.into_inner()).as_ref().and_then(|c| c.entries.get(&h))
|
||||
if let Some((k, out)) = CACHE.lock().unwrap_or_else(std::sync::PoisonError::into_inner).as_ref().and_then(|c| c.entries.get(&h))
|
||||
&& *k == key
|
||||
{
|
||||
return out.clone();
|
||||
|
||||
@@ -1973,7 +1973,7 @@ impl FontDb {
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut faces = self.faces.write().unwrap_or_else(|e| e.into_inner());
|
||||
let mut faces = self.faces.write().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let before = faces.len();
|
||||
for f in made {
|
||||
// Another thread may have added the same face meanwhile.
|
||||
@@ -2183,8 +2183,9 @@ impl FontDb {
|
||||
let face = |a: &Alias| a.paired.is_none() && a.style.is_some();
|
||||
let ps =
|
||||
self.read_faces().iter().flat_map(|f| Alias::of(&f.family, &f.style, &f.keys)).find(|(k, a)| *k == joined && face(a)).map(|(_, a)| a);
|
||||
let ps =
|
||||
ps.or_else(|| self.aliases.read().unwrap_or_else(|e| e.into_inner()).get(&joined).and_then(|v| v.iter().find(|a| face(a)).cloned()));
|
||||
let ps = ps.or_else(|| {
|
||||
self.aliases.read().unwrap_or_else(std::sync::PoisonError::into_inner).get(&joined).and_then(|v| v.iter().find(|a| face(a)).cloned())
|
||||
});
|
||||
if let Some(a) = ps {
|
||||
return (a.family, a.style.unwrap_or_else(|| style.to_string()));
|
||||
}
|
||||
@@ -2218,7 +2219,7 @@ impl FontDb {
|
||||
None => scanned(&self.read_catalog()).unwrap_or_default(),
|
||||
Some(traits) if traits.variable => traits,
|
||||
Some(traits) => {
|
||||
let variable = scanned(&self.catalog.read().unwrap_or_else(|e| e.into_inner())).is_some_and(|t| t.variable);
|
||||
let variable = scanned(&self.catalog.read().unwrap_or_else(std::sync::PoisonError::into_inner)).is_some_and(|t| t.variable);
|
||||
FontTraits { variable, ..traits }
|
||||
}
|
||||
}
|
||||
@@ -2625,11 +2626,11 @@ impl FontDb {
|
||||
return None;
|
||||
}
|
||||
let key = (face.id, gid);
|
||||
if let Some(i) = self.images.lock().unwrap_or_else(|e| e.into_inner()).kept.get(&key) {
|
||||
if let Some(i) = self.images.lock().unwrap_or_else(std::sync::PoisonError::into_inner).kept.get(&key) {
|
||||
return i.clone();
|
||||
}
|
||||
let image = face.skrifa().and_then(|f| crate::bitmap::glyph_image(&f, face.upem, gid)).map(Arc::new);
|
||||
self.images.lock().unwrap_or_else(|e| e.into_inner()).keep(key, image.clone());
|
||||
self.images.lock().unwrap_or_else(std::sync::PoisonError::into_inner).keep(key, image.clone());
|
||||
image
|
||||
}
|
||||
|
||||
@@ -2656,7 +2657,7 @@ impl FontDb {
|
||||
// stroke too.
|
||||
let coloured = Some((foreground.key(), stroke.filter(|_| svg).map(|c| c.key())));
|
||||
{
|
||||
let cache = self.colours.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let cache = self.colours.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
if let Some(c) = [None, coloured].iter().find_map(|k| cache.kept.get(&(face.id, gid, *k))) {
|
||||
return c.clone();
|
||||
}
|
||||
@@ -2668,7 +2669,7 @@ impl FontDb {
|
||||
crate::colr::colour_glyph(&f, face.location(), face.upem, gid, foreground)
|
||||
};
|
||||
let key = (face.id, gid, if used { coloured } else { None });
|
||||
self.colours.lock().unwrap_or_else(|e| e.into_inner()).keep(key, content.clone());
|
||||
self.colours.lock().unwrap_or_else(std::sync::PoisonError::into_inner).keep(key, content.clone());
|
||||
content
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,12 +261,12 @@ impl LibSymbol {
|
||||
pub(crate) struct SymbolLibraries;
|
||||
|
||||
impl LibraryKind for SymbolLibraries {
|
||||
const KIND: &'static str = "symbols";
|
||||
const OPEN: &'static str = "window.symbolLibrary";
|
||||
const LIST: &'static str = "symbol.libraries";
|
||||
const LOAD: &'static str = "symbol.loadLibrary";
|
||||
const MENU: &'static str = "Symbol Libraries Menu";
|
||||
const ADD: &'static str = "Add to Symbols";
|
||||
const KIND: &str = "symbols";
|
||||
const OPEN: &str = "window.symbolLibrary";
|
||||
const LIST: &str = "symbol.libraries";
|
||||
const LOAD: &str = "symbol.loadLibrary";
|
||||
const MENU: &str = "Symbol Libraries Menu";
|
||||
const ADD: &str = "Add to Symbols";
|
||||
/// Symbols need room to show their art.
|
||||
const VIEW: super::swatches::View = super::swatches::View::LargeThumb;
|
||||
type Lib = Arc<Vec<LibSymbol>>;
|
||||
|
||||
@@ -86,7 +86,7 @@ impl StylusFeed {
|
||||
}
|
||||
|
||||
fn lock(&self) -> MutexGuard<'_, Pen> {
|
||||
self.0.pen.lock().unwrap_or_else(|e| e.into_inner())
|
||||
self.0.pen.lock().unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
}
|
||||
|
||||
/// A pen turned to its tip moved with `pressure`, or `None`: another pointer moved
|
||||
|
||||
Reference in New Issue
Block a user