小编use*_*063的帖子

为什么在指针移动后分配给指针的成员仍然有效?

为什么n1_mut在这个例子中仍然有效?它已经被移入,Option::Some所以它不应该是无效的吗?

struct MyRecordRec2<'a> {
    pub id: u32,
    pub name: &'a str,
    pub next: Box<Option<MyRecordRec2<'a>>>
}

#[test]
fn creating_circular_recursive_data_structure() {
    let mut n1_mut = MyRecordRec2 {
        id: 1,
        name: "n1",
        next: Box::new(None)
    };

    let n2 = MyRecordRec2 {
        id: 2,
        name: "n2",
        next: Box::new(Some(n1_mut))
    };

    //Why is n1_mut still valid?
    n1_mut.next = Box::new(Some(n2));
}
Run Code Online (Sandbox Code Playgroud)

以下不使用熟悉的"使用移动值"错误编译:

#[test]
fn creating_and_freezing_circular_recursive_data_structure() {
    let loop_entry = {
        let mut n1_mut = MyRecordRec2 {
            id: 1,
            name: "n1",
            next: Box::new(None),
        };

        let …
Run Code Online (Sandbox Code Playgroud)

rust

14
推荐指数
1
解决办法
237
查看次数

TypeScript抱怨:找不到名称'通知'

我正在使用VS 2017和TS 2.2.1

我收到编译错误:找不到名称'通知'.

当我尝试声明通知时,TS抱怨它已经在packages\Microsoft.TypeScript.MSBuild.2.2.1\tools\tsc中声明.实际上,它定义为:

declare var Notification: {
    prototype: Notification;
    new(title: string, options?: NotificationOptions): Notification;
    requestPermission(callback?: NotificationPermissionCallback): Promise<string>;
}
Run Code Online (Sandbox Code Playgroud)

typescript typescript-typings visual-studio-2017

10
推荐指数
1
解决办法
1112
查看次数

为什么 OperationCancelledException 传递的 CancellationToken 与来自 CTSource 的 CancellationToken 不同?

为什么异常中存储的 CancellationToken 与 CancellationTokenSource 提供的令牌不同?

[Test]
public static async Task SqlCommand_should_recognise_which_CT_triggered_its_cancellation()
{

    var timeout = TimeSpan.FromSeconds(1);
    var cts = new CancellationTokenSource(timeout);

    try
    {
        var connection = new SqlConnection(_config.ConnectionString);
        await connection.OpenAsync(cts.Token);
        var sqlQuery = new SqlCommand("select 1", connection);

        await Task.Delay(timeout + TimeSpan.FromSeconds(1));
        await sqlQuery.ExecuteScalarAsync(cts.Token);
    }
    catch (OperationCanceledException cancelledEx)
    {
        //Shouldn't they be the same?
        Assert.AreEqual(cancelledEx.CancellationToken, cts.Token);
        // The below fails as well
        // Assert.IsTrue(cancelledEx.CancellationToken == cts.Token);


    }
}
Run Code Online (Sandbox Code Playgroud)

c# ado.net async-await

4
推荐指数
1
解决办法
299
查看次数

MassTransit/RabbitMq 错误队列 - 如何删除消息?

我有一个队列 {QueueName}。我定义了消费者和错误消息消费者如下:

                        cfg.ReceiveEndpoint
                        (
                            queueName: QueueName,
                            e =>
                            {
                                 e.UseMessageRetry(r => r.Immediate(2));

                                e.AutoDelete = false;
                                e.Durable = true;
                                e.Consumer(() => container.Resolve<My_Consumer>());
                                e.Consumer(() => container.Resolve<My_Fault_Consumer>());
                            }
                        );
                    
Run Code Online (Sandbox Code Playgroud)

当消费者耗尽处理消息的尝试次数时,故障消息消费者就会启动并通过记录错误来处理消息。我注意到创建了额外的队列,名为 {QueueName}_error。

My_Fault_Consumer 不确认故障消息消耗并且队列增长。

如何确认这些消息?

c# masstransit rabbitmq

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

在shim类中调用原始方法

我想针对一些错误的网络行为测试存储库.我使用MS Fakes伪造了这个类,它看起来像这样:

ShimInputRepository
                .AllInstances
                .UpdateEngagementStringNullableOfInt64NullableOfInt32String = (xInst, xEngId, xTrimUri, xTargetVers, xComments) =>
                    {


                        if (xEngId != initializer.SeededEngagementsWithoutEmp[3].EngagementId)
                        {
                            return xInst.UpdateEngagement(xEngId, xTrimUri, xTargetVers, xComments); //Unfortunately, calls recursively same method (not the original one)
                        }
                        else
                        {
                            throw new Exception
                                    (
                                        "An error occurred while executing the command definition. See the inner exception for details.",
                                        new Exception
                                        (
                                            "A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)"
                                        )
                                    ); …
Run Code Online (Sandbox Code Playgroud)

c# mstest shim microsoft-fakes

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

具有两个泛型参数的 F# 函数

如何使用显式泛型参数定义 f# 函数?

我尝试过这个:

let my_function<'a 'b>  (xs: 'a list) (ys: 'b list)  = ....
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

generics f#

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