问题列表 - 第317945页

如果死结构实现/派生某些特征,为什么 Rust 会停止检测它们?

在正常情况下,Rust 通过生成如下警告来警告结构是否死亡:

struct `Foo` is never constructed
Run Code Online (Sandbox Code Playgroud)

这对于检测可以删除的未使用类型很有用。

但是,我注意到编译器一旦实现或派生某些特征,就会停止对死结构发出警告。例如,对于仅包含以下内容的源文件:

struct `Foo` is never constructed
Run Code Online (Sandbox Code Playgroud)

编译器只会检测到DeadStruct1未使用,但不会检测到DeadStruct2,显然该程序中也没有使用它(Rust Playground上的示例):

warning: struct `DeadStruct1` is never constructed
 --> src/lib.rs:1:8
  |
1 | struct DeadStruct1;
  |        ^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
Run Code Online (Sandbox Code Playgroud)

我想知道为什么这个 lint 取决于结构是否实现特征?

rust

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

创建非对角线/移动窗口矩阵

如何用 R 创建非对角线/移动窗口矩阵?

> offdiag(3, 4, 6)

1 1 1 0 0 0
0 1 1 1 0 0
0 0 1 1 1 0
0 0 0 1 1 1 
Run Code Online (Sandbox Code Playgroud)

r matrix

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

为什么 EKEventStore().requestFullAccessToEvents() 适用于模拟器,但不适用于真实设备?

我正在构建一个 iOS 应用程序,它可以在 iOS 日历中以编程方式创建事件。我的代码在任何 iOS 模拟器中运行时都可以完美运行。但当安装在任何物理设备中时,它根本就不会。我究竟做错了什么?

当调用 requestAccess() 函数时,无论是在 onAppear 方法上还是在按钮内,它都不起作用。这似乎是一个身份验证问题,但没有理由它在模拟器中工作而不是在物理设备中工作。

有人遇到过同样的问题吗?有什么想法吗?或者推荐?

import Foundation
import EventKit

class EventModel {
    
    let eventStore  = EKEventStore()
    let todayDate : Date = Date()
    
    func requestAccess() {
        let status = EKEventStore.authorizationStatus(for: .event)
        if status == .authorized {
            print("Access is already granted.")
        } else {
            print(status.rawValue)
            eventStore.requestFullAccessToEvents { success, error in
                if success && error == nil {
                    print("Access has been granted.")
                } else {
                    print(error)
                    print("Access request failed with error: \(error?.localizedDescription ?? "Unknown error")") …
Run Code Online (Sandbox Code Playgroud)

calendar ios eventkit swift swiftui

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

为什么我在 Android 14 上执行代码时遇到“在没有类型的情况下启动 FGS”错误?

代码 A 在 Android 13 或更低版本中运行良好,但在 Android 14 中运行时出现错误 A?

我该如何修复它?

代码A

 private fun startForegroundService() {
        val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {            
            val  mChannelName = getString(R.string.app_name)
            val notificationManager = this.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

            val notificationChannel = NotificationChannel(
                CHANNEL_ID,
                mChannelName,
                NotificationManager.IMPORTANCE_LOW 
            )
            notificationManager.createNotificationChannel(notificationChannel)
            NotificationCompat.Builder(this, notificationChannel.id)
        } else {
            NotificationCompat.Builder(this)
        }

        val myIntent = Intent(this, ActivityMain::class.java)        
     
        myIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
        
        val pendingIntent = PendingIntent.getActivity(
            this,
            0,
            myIntent,
            PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
        )

        builder.setSmallIcon(R.drawable.notify_icon)            
            .setContentTitle(getString(R.string.notificationTitle))
            .setTicker(getString(R.string.notificationTicker ))      //It will show text on status …
Run Code Online (Sandbox Code Playgroud)

android kotlin

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

为什么嵌套可组合项的所有父可组合项都会被重组?

我有一个简单的测试应用程序:

主要活动:

        ...
        setContent {
            TestTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    TestScreen()
                }
            }
        }
        ....
Run Code Online (Sandbox Code Playgroud)

测试屏幕:

@Composable
fun TestScreen(testViewModel: TestViewModel = viewModel()) {
    Log.i("Test", "A")
    Column {
        Log.i("Test", "B")
        Column {
            Log.i("Test", "C")
            Column {
                Log.i("Test", "D")
                OutlinedTextField(
                    value = testViewModel.textField,
                    onValueChange =  testViewModel::updateTextField
                )
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

测试视图模型:

class TestViewModel : ViewModel() {
    var textField by mutableStateOf("")
        private set

    fun updateTextField(v: String) {
        textField = v
    }
}
Run Code Online (Sandbox Code Playgroud)

对于 的每次键盘点击,我都会看到、、和OutlinedTextField的所有日志。我的期望是,在最初的组合之后我实际上不会看到任何日志,因为这是国家的唯一依赖。 …

android android-jetpack-compose

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

为什么 Line-clamp 在标签按钮上不起作用?

尝试在按钮元素上应用线夹时遇到问题:

<button style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical;  
 -webkit-line-clamp: 1">
        long text inside my button
 </button>
Run Code Online (Sandbox Code Playgroud)

但是,当将其应用于按钮内的范围时,它会起作用:

<button>
   <span style="overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; - 
    webkit-line-clamp: 1">
        long text inside my span
   </span>
</button>
Run Code Online (Sandbox Code Playgroud)

它不适用于按钮元素(例如用户代理样式表)是否有原因?

请注意,我不想在所有按钮中使用跨度,因此它们只能适合一行。对于我的测试,它适用于所有其他 html 标签(a、p、...)

html css

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

DevOps Pipeline 突然无法访问工件 nuget feed。未经授权

我今天遇到了一个随机发生的问题,即我的所有 DevOps Pipelines 无法再访问我的 NuGet feed,这是一个 DevOps Artifact。

我有一个任务负责安装 AzureSignTool,下面是该任务的 YAML。windows-latest我正在Microsoft 托管代理上使用该图像。

- task: CmdLine@2
  displayName: 'Install AzureSignTool'
  inputs:
    script: |
      set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
      dotnet tool install --global AzureSignTool --version 4.0.1
Run Code Online (Sandbox Code Playgroud)

这是因以下错误而失败的任务。

未处理的异常:NuGet.Protocol.Core.Types.FatalProtocolException:无法加载 source 的服务索引。---> System.Net.Http.HttpRequestException:响应状态代码不表示成功:401(未经授权)。

我已经检查了提要的权限,并且可以确认它们Project\Build Administrators已设置为所有者。

我还尝试了各种其他操作,包括更改代理上的 NuGet 版本、更改 AzureSignTool 的版本等。

我应该检查哪些权限/设置?

更新

因此,我将 RestoreNuGetPackages 任务移到 InstallAzureSignTool 之前,并且该任务成功,因此显然它可以毫无问题地进行身份验证。

然而任务仍然失败。我什至添加了--ignore-failed-sources但这没有效果。

错误消息已更改,但根本问题是相同的。

[NuGet Manager] [Info] GET https://api.nuget.org/v3/registration5-gz-semver2/azuresigntool/index.json

[NuGet Manager] [Info] GET https://{ORG}.pkgs.visualstudio.com/_packaging/{GUID}/nuget/v3/registrations2-semver2/azuresigntool/index.json

[NuGet Manager] [Info] Unauthorized https://{ORG}.pkgs.visualstudio.com/_packaging/{GUID}/nuget/v3/registrations2-semver2/azuresigntool/index.json 767ms

[NuGet Manager] [Info] OK https://api.nuget.org/v3/registration5-gz-semver2/azuresigntool/index.json 1010ms

Unhandled …
Run Code Online (Sandbox Code Playgroud)

azure-pipelines azure-artifacts

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

Core 和 Classic PowerShell 中开关块中的 Return 行为不同

以下脚本在 5.1 和 7.4.0 上运行时给出不同的结果。

function foo($x) {
    $val = switch ($x){
        1 { 5 }
        default {
            return 10 
        }
    }
    Write-Host "Val is $val" 
    $val + 1
}

Write-Host "foo 1: $(foo 1)" 
Write-Host "foo 2: $(foo 2)" 
Run Code Online (Sandbox Code Playgroud)

PS 5.1 输出:

Val is 5
foo 1: 6
foo 2: 10
Run Code Online (Sandbox Code Playgroud)

PS 7.4.0 输出:

Val is 5
foo 1: 6    
foo 2:
Run Code Online (Sandbox Code Playgroud)

这是 PS Core 中的错误(这对我来说肯定是出乎意料的)还是这是一个记录在案的更改/始终是未定义的行为?

powershell powershell-core

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

DRY:C++11 枚举类与 C 枚举

我有这样的课程:

struct InsertResult{
    enum class Status{
        INSERTED            ,
        UPDATED_IN_PLACE    ,
        REPLACED            ,
        SKIP_INSERTED       ,
        ERROR_NO_MEMORY     ,
        ERROR_INVALID       ,
        ERROR
    };

    bool        ok;
    Status      status;
    // more members here...

    // spill the enum:
    constexpr static auto INSERTED          =  Status::INSERTED         ;
    constexpr static auto UPDATED_IN_PLACE  =  Status::UPDATED_IN_PLACE ;
    constexpr static auto REPLACED          =  Status::REPLACED         ;
    constexpr static auto SKIP_INSERTED     =  Status::SKIP_INSERTED    ;
    constexpr static auto ERROR_NO_MEMORY   =  Status::ERROR_NO_MEMORY  ;
    constexpr static auto ERROR_INVALID     =  Status::ERROR_INVALID    ;
    constexpr static auto ERROR             =  Status::ERROR …
Run Code Online (Sandbox Code Playgroud)

c++ dry enum-class c++17

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

ch() 函数出错

我点击 td 时出错。为什么?

function ch() {
  console.log("cliked")
}
Run Code Online (Sandbox Code Playgroud)
<table>
  <tr>
    <td onclick='ch()'>
      click on td
    </td>
  </tr>
</table>

<div onclick="ch()">click on div</div>
Run Code Online (Sandbox Code Playgroud)

javascript

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