rust


How to parse i64 from a string? [duplicate]


This question already has an answer here:
Convert a String to int in Rust?
4 answers
Apparently, something has changed and thus I can't parse i64 from string:
use std::from_str::FromStr;
let tree1: BTreeMap<String, String> = //....
let my_i64: i64 = from_str(tree1.get("key1").unwrap().as_slice()).unwrap();
Error:
16:27 error: unresolved import `std::from_str::FromStr`. Could not find `from_str` in `std`
$ rustc -V
rustc 1.0.0-nightly (4be79d6ac 2015-01-23 16:08:14 +0000)
Your import fails because FromStr trait is now in str::str::FromStr. Also, from_str is no longer in the prelude. The preferred way to convert strings to integers now is the recently added std::str::StrExt::parse.
fn main() {
let i = "123".parse::<i64>();
println!("{:?}", i);
}
prints
Some(123)
Demo

Related Links

Drop a Rust void pointer stored in an FFI
Iterate two vectors and the rest of the larger one
How do I implement Clone/Copy for an enum that contains a String?
Modeling embedded hardware in Rust and how to have multiple mutable references cleanly?
Should I borrow or copy my small data types?
Using pointer casting to change the “type” of data in memory [duplicate]
Export function only to module test?
Take slice of certain length known at compile time
Is it possible to deactivate file locking in cargo?
“does not live long enough” error in same function
What ways exist to create containers of several types? [duplicate]
How can I optimize reading a UTF-8 string from a file with a known offset and size?
Create vector of objects implementing a trait in Rust
Using loop variable from “..” loop causes type conversion?
What is RFC 401's coerce_inner useful for?
Rust Borrow checker only complains about borrowing as mutable multiple times when a function that returns a reference with the same lifetime assigned

Categories

HOME
gaming
workflow
add-on
command-prompt
filesize
semantic-web
google-sheets-query
flurry
gprs
angular2-template
sympy
cisco
jpa-criteria
sharepoint-online
slide
parsley.js
google-tasks-api
vertica
user-defined-types
clr
unity-container
workday
perfino
microprocessors
es6-modules
delayed-job
universal
caesar-cipher
nest
payeezy
cmis
spring-rabbitmq
java-stream
char-pointer
transform
grails-2.5
dreamfactory
nanogallery
reset
microkernel
angular-datatables
elasticsearch-aggregation
spongycastle
roracle
ilrepack
test-data
predicates
.when
wildfly-9
controllers
java-2d
system.web.optimization
odp.net-managed
jeditable
android-expansion-files
voronoi
cortana
boost-proto
juniper-network-connect
canopy
featuretoggle
gql
android-handler
wicked-gem
tidyr
thoughtworks-go
hp-idol-ondemand
symja
adwords-apiv201402
nesper
map
meteorite
particle-swarm
smips
colon
google-code-prettify
bcdedit
eager-loading
chefspec
android-authenticator
email-verification
arrow
telerik-ajax
pcspim
hardcode
asio
haiku
server-variables
botnet
airprint
3des
eaccelerator
outlook-2007-addin
sscli
android-input-method
self-tracking-entities
mysqli-multi-query
watchpoint
error-detection
webclient.uploaddata

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App