e.g., If there was an example that said, "match on a specific codepoint by doing `http://re.is _match(codepoint.encode_utf8(&mut [0; 4]))`" that might be enough. https://play.rust-lang.org/?gist=79cd9455d12d186af21ae685f6f909fb&version=stable …
-
-
Replying to @burntsushi5
I would never have thought to turn a char into a &str that way! I wonder if it means we should add char as_str(&self) -> &str
2 replies 0 retweets 0 likes -
Replying to @wycats
Hmm. Don't think that would work. You would need to return an array, but we don't have a type for "fixed size array whose contents are guaranteed to be UTF-8."
1 reply 0 retweets 0 likes -
Replying to @burntsushi5
I mean once you have the &[u8] can't you read it into a &str? Where would the unsafety come from?
1 reply 0 retweets 0 likes -
Replying to @wycats @burntsushi5
I don't think you can get a &[u8] for anything other than ASCII, since the in-memory representation is different between `char` and UTF-8. Would have to be owned
1 reply 0 retweets 0 likes -
1 reply 0 retweets 0 likes
-
Replying to @sgrif @burntsushi5
You could read the data into a new fixed size UTF8 stack array (doing the conversion) and then read it into the &str.
1 reply 0 retweets 0 likes -
What is the lifetime of your &str? Where does it point to?
2 replies 0 retweets 1 like -
Replying to @burntsushi5 @sgrif
Couldn't you stack allocate another four bytes (or 8 if needed) and unsafely write into it after validating?
1 reply 0 retweets 0 likes -
I would suggest trying to write the code. The nature of Twitter prevents me from understanding where you've gone wrong. :-)
1 reply 0 retweets 0 likes
+1 I've been travelling through this entire convo so I haven't had a chance yet.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.