[librsvg: 6/7] Use TryFrom instead of the cast crate for usize -> u32




commit 529d1c30c54e7329d0be687f8f3f18b61d0887c2
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 26 12:18:05 2021 -0500

    Use TryFrom instead of the cast crate for usize -> u32
    
    See https://github.com/japaric/cast.rs/issues/20
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/622>

 src/text.rs | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/src/text.rs b/src/text.rs
index a865c7381..09b7a8e9a 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -2,6 +2,7 @@
 
 use markup5ever::{expanded_name, local_name, namespace_url, ns};
 use std::cell::RefCell;
+use std::convert::TryFrom;
 use std::rc::Rc;
 
 use crate::bbox::BoundingBox;
@@ -1226,8 +1227,9 @@ fn add_pango_attributes(
     start_index: usize,
     end_index: usize,
 ) {
-    let start_index: u32 = cast::u32(start_index).expect("Pango attribute index must fit in u32");
-    let end_index: u32 = cast::u32(end_index).expect("Pango attribute index must fit in u32");
+    let start_index = u32::try_from(start_index).expect("Pango attribute index must fit in u32");
+    let end_index = u32::try_from(end_index).expect("Pango attribute index must fit in u32");
+    assert!(start_index <= end_index);
 
     let mut attributes = Vec::new();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]