对于一维,代码模型是:
fn main() {
let a = vec![1, 2, 3, 4, 5];
print_it(&a); // :)
}
fn print_it(p: &[usize]) {
println!("{:?}", p);
}
Run Code Online (Sandbox Code Playgroud)
我尝试对二维向量应用等效逻辑,但它不起作用
fn main() {
let a: Vec<Vec<usize>> = vec![
vec![1,2,3,4,],
vec![5,6,7,8,],
];
print_it(&a); // :( expected slice `[&[usize]]`, found struct `Vec`
}
fn print_it(p: &[&[usize]] ) {
println!("{:?}", p);
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在将一些 Windows 程序迁移到 Web 技术。基本上使用System.Drawing,所以我使用JavaScript,当然还有Canvas。作为概念实践,我尝试在画布上绘制网格(见图),酷,我非常接近,但我无法获得暗线交替的颜色。我应该怎么办?
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.translate(0.5, 0.5) // waiting a line of one pixel
let shift = 0;
let w = canvas.clientWidth;
while (shift <= w) {
ctx.strokeStyle = shift % 40 == 0 ? 'gray' : 'silver';
ctx.moveTo(shift, w)
ctx.lineTo(w, w - shift);
shift += 10;
}
ctx.stroke();Run Code Online (Sandbox Code Playgroud)
<canvas id="canvas" class="plot" width="300" height="300"></canvas>Run Code Online (Sandbox Code Playgroud)
如何在 JavaScript 中保留一组常量?
同样,在比较时,它给了我正确的结果。
例子,
const vector = [1, 2, 3, 4];
vector[2] = 7; // An element is not constant!
console.log(JSON.stringify(vector));
// [1,2,7,4] ... Was edited
// OR
const mirror = [1, 2, 7, 4];
console.log(`are equals? ${vector == mirror}`);
// false !
Run Code Online (Sandbox Code Playgroud) 从 SQL Server 获取 JSON 很棒,但我遇到了问题。例子。我有一个LithologySamples具有非常基本结构的表:
[Id] [uniqueidentifier],
[Depth1] [real],
[Depth2] [real],
[RockId] [nvarchar](8),
Run Code Online (Sandbox Code Playgroud)
数据库中该表大约有 600 条记录。我想生成 JSON 以将数据传输到另一个数据库,因此我使用FOR JSON AUTO. 这与其他记录较少的表完美配合。但在这种情况下,我发现生成的响应不完整。让我很困惑。我在检查输出时注意到:
[Id] [uniqueidentifier],
[Depth1] [real],
[Depth2] [real],
[RockId] [nvarchar](8),
Run Code Online (Sandbox Code Playgroud)
我已经搜索过,但找不到任何选项来完整地给出答案。
SQL查询如下:
[{
"Id": "77769039-B2B7-E511-8279-DC85DEFBF2B6",
"Depth1": 4.2000000e+001,
"Depth2": 5.8000000e+001,
"RockId": "MIC SST"
}, {
"Id": "78769039-B2B7-E511-8279-DC85DEFBF2B6",
"Depth1": 5.8000000e+001,
"Depth2": 6.3000000e+001,
"RockId": "CGL"
}, {
"Id": "79769039-B2B7-E511-8279-DC85DEFBF2B6",
"Depth1": 6.3000000e+001,
"Depth2": 8.3000000e+001,
"RockId": "MIC SST"
}, {
// ... OK, continue fine, but it breaks off towards the …Run Code Online (Sandbox Code Playgroud)