小编Dan*_*ath的帖子

在Java中单击按钮创建菜单

对于一个项目,我们想要创建一个按钮,当它被点击时会产生一个小菜单(它的工作方式类似于Firefox中的后退按钮的下拉菜单,尽管激活的方式是简单的左键单击).唯一真正的限制是它必须是Java(如果可能的话,最好是摆动).那么,任何想法,例子,代码如何做到这一点?

java user-interface

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

什么是确定字符是否在Unicode范围内的最简单方法,在Rust中?

我正在寻找最简单的方法来确定Rust中的字符是否在两个Unicode值之间.

例如,我想知道字符s是否在[#x1-#x8]或之间[#x10FFFE-#x10FFFF].有没有这样做的功能?

unicode-string rust

3
推荐指数
2
解决办法
1338
查看次数

将字符串转换为小写

如何将字符串转换为小写或执行某种等效比较忽略大小写?在Ascii类型上有一个忽略的情况,但它似乎令人费解,我没有看到转换str为的方法Ascii.

string case-sensitive rust

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

找出关闭的返回类型

fn filter在下面的示例中,我遇到了解决函数类型签名的麻烦.

Node和Descendant定义仅用于语法.它不是要做任何事情!

use std::iter::Filter;

#[derive(Clone)]
pub struct Node<'a> {
   s: &'a str,
}

pub struct Descendants<'a>{
    iter: Node<'a>
}

impl<'a> Iterator for Descendants<'a> {
    type Item = Node<'a>;

    fn next(&mut self) -> Option<Node<'a>> {
        Some(Node {s: self.iter.s})
    }
}

impl<'a> Node<'a> {
    pub fn descendants(&self) -> Descendants<'a> {
        Descendants{ iter: Node{s: self.s} }  
    }

    pub fn filter(&self, criteria: &str) -> Filter<Descendants<'a>, fn(&'a Node<'a>)->bool > {
        self.descendants()
            .filter(|node| node.s == "meh")
    }
}

fn main() {
    let doc = …
Run Code Online (Sandbox Code Playgroud)

iterator rust

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

是否可以在Vec中存储类型,而不是这些类型的实例?

是否有可能以Vec某种形式存储不同的Rust类型,以便我可以在以后获取类型?

我可以存储TypeId任何类型的,但TypeId据我所知,我不能使用它来回到原始类型.

用Java术语,我想创建一个[boolean.class, char.class, ...]等等.

generics reflection rust

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

在实现两个段错误的类型上从特征A转换为特征B.

几天前,有一个关于OOP的问题想要使用downcast来解决这个问题.作为一个自我挑战,我试图解决使用std::mem::transmute和不安全块的问题,这产生了分段错误.

这是Rust Playground完整代码.

代码的违规部分是这样的:

unsafe {
    let storage =
        mem::transmute::<&mut Box<AnyStorable + 'static>, &mut Box<Insertable<C>>>(x);
    println!("{:#?}", x);
    storage.insert(component); // This segfaults
};
Run Code Online (Sandbox Code Playgroud)

运行时会产生段错误:

/root/entrypoint.sh:line 7:5分段错误超时--signal = KILL $ {timeout}"$ @"

但是,当我更换此行时:

let storage =
    mem::transmute::<&mut Box<AnyStorable + 'static>, &mut Box<Insertable<C>>>(x);
Run Code Online (Sandbox Code Playgroud)

有:

let storage =
    mem::transmute::<&mut Box<AnyStorable + 'static>, &mut Box<VecStorage<C>>>(x);
Run Code Online (Sandbox Code Playgroud)

有用.为什么第一行失败而第二行没有?

unsafe segmentation-fault rust

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

当我将 `ConcurrentDictionary` 转换为 `IDictionary` 时出现奇怪的并发行为

我有以下测试:

using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;               

public class Program
{
    public static void Main()
    {
        IDictionary<string, string> dictionary = new ConcurrentDictionary<string, string>(); // FAILS sometimes
        // ConcurrentDictionary<string, string> dictionary = new ConcurrentDictionary<string, string>(); // WORKS always

        Parallel.For(0, 10, i => dictionary.TryAdd("x1", "y1"));
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我在 .NET Fiddle 中运行它,有时会出现以下异常:

未处理的异常。System.AggregateException:发生一个或多个错误。(该键已存在于字典中)
System.ArgumentException:该键已存在于字典中。

在 System.Collections.Concurrent.ConcurrentDictionary`2.System.Collections.Generic.IDictionary<TKey,TValue>.Add(TKey key, TValue value)
在 System.Collections.Generic.CollectionExtensions.TryAdd[TKey,TValue](IDictionary` 2 字典,TKey 键,TValue 值)
在 Program.<>c__DisplayClass0_0.b__0(Int32 i)
在 System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.b__1(RangeWorker& currentWorker, Int64 timeout, Boolean&replicationDelegateYieldedBeforeCompletion)
---之前位置的堆栈跟踪结束 ---
在 System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`2.b__1(RangeWorker& currentWorker, Int64 timeout, Boolean&replicationDelegateYieldedBeforeCompletion)
在 …

.net c# concurrency thread-safety concurrentdictionary

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

Haskell中数据类型的别名

所以我有一个像这样的结构:

data Maybe a = Nothing | Just a  
Run Code Online (Sandbox Code Playgroud)

但我想要一个定义为的结构

data MaybeInt = Nothing | Just Int
Run Code Online (Sandbox Code Playgroud)

有没有办法定义MaybeInt使用Maybe a,如果有,如何?

haskell types

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