在每晚的Rust中,不再可能将字符串文字指定为带有"〜"字符的 String .
例如,在C++中,我使用用户定义的文字连接字符串文字,而不是std::string
每次都提到的外壳:
inline std::string operator"" _s (const char* str, size_t size) {return std::string (str, size);}
foo ("Hello, "_s + "world!");
Run Code Online (Sandbox Code Playgroud)
在Rust中是否存在类似的功能,以使字符串文字连接不那么痛苦String::from_str ("Hello, ") + "world!"
?
当我import etc.c.curl;
DMD告诉我
Warning 2: File Not Found curl.lib
Run Code Online (Sandbox Code Playgroud)
这个curl.lib在哪里?
(我已经尝试了几个来自http://curl.haxx.se/download.html的软件包但是没有找到curl.lib.MSVC软件包libcurl-7.19.3-win32-ssl-msvc.zip
有一个curllib.lib
但是DMD不会与它链接.)
由于缺少一个更好的例子,假设我想用Rust编写一个简单的客户端,可以建立连接并从Twitter的HTTP Streaming API接收数据.这可能吗?我一直在关注Iron和Nickel,这似乎是一个很好的框架,但我不认为他们有这个功能呢?
所以我试图在字符串中找到模式并将其转换为整数。
首先我寻找一个字符串:
let haystack = "HTTP/1.1 200\r\n";
let needle = "HTTP/1.";
let http_location = haystack.rfind(needle);
if (http_location.is_some()) {
Run Code Online (Sandbox Code Playgroud)
现在我已经找到了它,我可以想出两种方法来获取数字状态。任何一个:
let mut temp_str = haystack.char_at(http_location.unwrap());
let status = String::from_str(temp_str);
}
Run Code Online (Sandbox Code Playgroud)
或者:
let status = String::from_str(&haystack[http_location.unwrap()]);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,它们都已被弃用(而且可能是错误的)。目前这样做的正确方法是什么?
另外,这部分的风格正确吗?:
let http_location = haystack.rfind(needle);
if (http_location.is_some())
Run Code Online (Sandbox Code Playgroud)