I'm trying to use the unicode-segmentation crate in some macros I'm writing. I've added "unicode-segmentation" = "version = "^0.1.2" to my Cargo.toml file. Then I added "extern crate unicode_segmentation" and "use unicode_segmentation::UnicodeSegmentation" all over the place. I put it in lib.rs
, I put it in the file I use it in, I put it in the test module (it only complains when I run cargo test
), I even put it directly in the macro definition (which actually helped with the same problem I had trying to use HashSets), but to no avail. I just get more error: can't find crate for unicode_segmentation
and error: unresolved import unicode_segmentation::*. Did you mean self::unicode_segmentation?
and error: unresolved name UnicodeSegmentation::grapheme_indices
errors. I've also tried pub use
everywhere too.
I'm not going to show you all the different places I try to declare it, but here's one attempt:
#[macro_export]
macro_rules! take_till_s (
($input:expr, $submac:ident!( $($args:tt)* )) => (
{
extern crate unicode_segmentation;
use unicode_segmentation::*;
let mut offset = $input.len();
for (o, s) in UnicodeSegmentation::grapheme_indices($input, true) {
if $submac!(s, $($args)*) {
offset = o;
break;
}
}
if offset < $input.len() {
$crate::IResult::Done(&$input[offset..], &$input[..offset])
} else {
$crate::IResult::Done("", $input)
}
}
);
($input:expr, $f:expr) => (
take_till_s!($input, call!($f));
);
);
I have other macros where declaring HashMap inside the macro finally got the compiler to recognize the import, but no such luck in this case. What could I possibly do to use the unicode_segmentation crate in my macros?