我有这样的网址:
http%3A%2F%2Fexample.com%3Fa%3D1%26b%3D2%26c%3D3
Run Code Online (Sandbox Code Playgroud)
我解析它hyper::Url::parse并获取查询字符串:
let parsed_url = hyper::Url::parse(&u).unwrap();
let query_string = parsed_url.query();
Run Code Online (Sandbox Code Playgroud)
但它给了我一个字符串的查询.我想获取查询字符串HashMap.这样的事情:
// some code to convert query string to HashMap
hash_query.get(&"a"); // eq to 1
hash_query.get(&"b"); // eq to 2
Run Code Online (Sandbox Code Playgroud) 我正在创建一个应用程序phonegap,我想从我的应用程序打开Telegram组或频道.
换句话说,当我点击一个组时,Telegram打开,该组显示给用户.
我使用了以下代码,但我不知道如何切换到特定的@username页面:
var username = 'http://telegram.me/telegram';
navigator.startApp.start("org.telegram.messenger", function(message) { /* success */
console.log(message); // => OK
},
function(error) { /* error */
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
我试过tg:resolve?domain=username在浏览器中打开但我的浏览器给我一个错误:
net::ERR_UNKNOWN_URL_SCHEME
我正在研究 CQRS 模式,我们的团队希望在 PHP 中开发基于 CQRS 的系统。
我知道我们可以在 PHP 中模拟事件系统,但我发现如果编程语言是基于事件的,CQRS 实现更好/更容易(我不确定这一点)。
我有两个问题:
我想知道如果我们在 PHP 中通过 CQRS 模式开发我们的系统可能是可靠的还是切换到其他(基于事件的)编程语言给我们更多的一致性?
CQRS在微服务系统中有哪些好处?有没有其他可靠且易于实现的模式?
为了编写游戏,我需要在终端的不同位置写一些字符.我用了
println!("{c:>width$}", c="*", width=x);
Run Code Online (Sandbox Code Playgroud)
这个x位置几乎没问题,但是y当我按下时我想改变位置space.有什么办法吗?
我正在创建一个简单的HTTP服务器.我需要读取请求的图像并将其发送到浏览器.我正在使用此代码:
fn read_file(mut file_name: String) -> String {
file_name = file_name.replace("/", "");
if file_name.is_empty() {
file_name = String::from("index.html");
}
let path = Path::new(&file_name);
if !path.exists() {
return String::from("Not Found!");
}
let mut file_content = String::new();
let mut file = File::open(&file_name).expect("Unable to open file");
let res = match file.read_to_string(&mut file_content) {
Ok(content) => content,
Err(why) => panic!("{}",why),
};
return file_content;
}
Run Code Online (Sandbox Code Playgroud)
如果请求的文件是基于文本的,则此方法有效,但是当我想要读取图像时,我收到以下消息:
流不包含有效的UTF-8
它是什么意思以及如何解决它?
我有这样的界面:
type ViewInterface interface{
Init() View
}
type View struct{
Width int
Height int
}
Run Code Online (Sandbox Code Playgroud)
所以我从View创建了一个新类型
type MainView View
func (m MainView) Init() MainView{
return MainView{
Width:10,
Height:10,
}
}
Run Code Online (Sandbox Code Playgroud)
然后我将MainView传递给以下方法:
func Render(views ...ViewInterface){
for _, view := range views {
v := view.Init()
}
}
func main() {
Render(MainView{})
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
不能使用MainView文字(类型MainView)作为Render参数中的类型ViewInterface:MainView没有实现ViewInterface(Init方法的错误类型)
有Init()MainView
想要Init()视图
为什么MianView不一样View?解决这个问题的正确方法是什么?
谢谢
如何检查变量(由用户输入)是一个数字,如int,float或其他什么?
我想用match表达式做到这一点:
let mut input = String::new();
io::stdin().read_line(&mut input);
let result = match input {
// !!??
}
Run Code Online (Sandbox Code Playgroud)
有可能match吗?
我想使用regexcrate并从字符串中捕获数字.
let input = "abcd123efg";
let re = Regex::new(r"([0-9]+)").unwrap();
let cap = re.captures(e).unwrap().get(1).unwrap().as_str();
println!("{}", cap);
Run Code Online (Sandbox Code Playgroud)
如果存在数字input,它会起作用,但如果数字不存在,input我会收到以下错误:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'
Run Code Online (Sandbox Code Playgroud)
如果正则表达式不匹配,我希望我的程序继续.我该如何处理这个错误?