我写了正则表达式验证URL,可能就像
example.com
www.example.com
所有4个都在工作
现在,如果我输入的文本(www.example.com - thisisincorrect),它允许我输入并保存到db
我使用的正则表达式是:
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Run Code Online (Sandbox Code Playgroud)
和
([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Run Code Online (Sandbox Code Playgroud)
请帮忙!
我有一个枚举:
enum Group {
OfTwo {
first: usize,
second: usize,
},
OfThree {
one: usize,
two: usize,
three: usize,
},
}
Run Code Online (Sandbox Code Playgroud)
我想编写一个仅将Group::OfTwo变体作为参数的函数:
fn proceed_pair(pair: Group::OfTwo) {}
Run Code Online (Sandbox Code Playgroud)
但当我这样做时,我收到消息:
error[E0573]: expected type, found variant `Group::OfTwo`
--> src/lib.rs:13:23
|
13 | fn proceed_pair(pair: Group::OfTwo) {}
| ^^^^^^^^^^^^
| |
| not a type
| help: try using the variant's enum: `crate::Group`
Run Code Online (Sandbox Code Playgroud)
有办法实现这一点吗?
还有就是网格布局中VS-代码,并且在终端面板。有没有办法将两者结合起来?
可以说我想要这个:
--------------------------------------------------------------
| | |
| | |
| | |
| | something |
| | here |
| editor here | |
| | |
| | |
| |---------------------------|
| | |
| | |
| | terminal |
| | here |
| | |
| | |
| | |
--------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
我知道我们可以把终端放在右边,但我不知道我们是否可以把它放在右栏的底部。不过,它可以与其他面板一起使用,例如编辑器。
我知道我可以对哈希图使用整数键,就像下面的字典示例一样。但是字典是无序的,不能从整数键中受益。
julia> hashmap = Dict( 5 => "five", 9 => "nine", 16 => "sixteen", 70 => "seventy")
Dict{Int64,String} with 4 entries:
9 => "nine"
16 => "sixteen"
70 => "seventy"
5 => "five"
julia> hashmap[9]
"nine"
julia> hashmap[8:50] # I would like to be able to do this to get keys between 8 and 50 (9 and 16 here)
ERROR: KeyError: key 8:50 not found
Stacktrace:
[1] getindex(::Dict{Int64,String}, ::UnitRange{Int64}) at ./dict.jl:477
[2] top-level scope at REPL[3]:1
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种有序结构,它允许访问一定范围内的所有键,同时由于排序键而受益于性能优化。
我是Rust的新手,在文档中找不到将hashmap的值收集到向量中的方法。
假设我有一个哈希图:
score_table: HashMap<Id, Score>
我想所有的Score成Vec
all_scores: Vec<Score>
我很想使用,values但由于值不是vec,所以它不起作用:
all_scores = score_table.values()
我知道可以Values实现该ExactSizeIterator特征,但是我不知道如何将迭代器的所有值收集到向量中,而无需手动编写for循环并将向量中的值一个接一个地推入。
[编辑1]
我还尝试着use std::iter::FromIterator;降落到类似:
all_scores = Vec::from_iter(score_table.values());
Run Code Online (Sandbox Code Playgroud)
expected type `std::vec::Vec<Score>`
found type `std::vec::Vec<&Score>`
Run Code Online (Sandbox Code Playgroud)
[编辑2]
由于这个问题,我将其更改为:
all_scores = Vec::from_iter(score_table.values().cloned());
Run Code Online (Sandbox Code Playgroud)
并且不会对产生错误cargo check。
这是一个好方法吗?
我有一个类重新定义默认的下标赋值(subsasgn).由于它是memmapfile的包装器,我不需要subsasgn的返回值,所以如何忽略它呢?
链接到这个问题,但试图忽略所有返回的参数:
dummy = subsasgn(self.mmap.Data.bit, newSub, value);
Run Code Online (Sandbox Code Playgroud)