小编Ale*_*ley的帖子

如何将 2D vec 作为切片传递给函数?

对于一维,代码模型是:

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)

我究竟做错了什么?

rust

4
推荐指数
2
解决办法
69
查看次数

Canvas 中循环内的笔颜色变化

我正在将一些 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 html5-canvas

3
推荐指数
1
解决办法
181
查看次数

JavaScript 中的常量数组

如何在 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)

javascript node.js

2
推荐指数
1
解决办法
105
查看次数

问题 where 子句 FOR JSON AUTO 生成了不完整的答案

从 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)

t-sql sql-server

0
推荐指数
1
解决办法
1105
查看次数

标签 统计

javascript ×2

html5-canvas ×1

node.js ×1

rust ×1

sql-server ×1

t-sql ×1