小编Wil*_*Roe的帖子

参数要求 _ 被借用于 'static - 我该如何解决这个问题?

我有一个来自 Rust 编译器的生命周期/借用错误,我无法理解。问题似乎是 Rust 假设当一个参数传递给一个返回静态值引用的函数时,该参数引用也必须是静态的。

#[derive(Debug)]
struct TestThingy<'a> {
    label: &'a str,
}

const TEST_VALUES: [TestThingy; 3] = [
    TestThingy { label: "one" },
    TestThingy { label: "two" },
    TestThingy { label: "three" },
];

pub fn value_for_num(num: &str) -> Option<&'static TestThingy> {
    TEST_VALUES.iter().find(|value| value.label == num)
}

pub fn test_out_thingy() {
    let tmp_val = String::from("two");
    if let Some(test_thingy) = value_for_num(&tmp_val) {
        println!("test_thingy: {:?}", test_thingy);
    }
}

fn main() {
    test_out_thingy();
}
Run Code Online (Sandbox Code Playgroud)

Rust 错误:error[E0597]: `tmp_val` does not live long …

rust

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

Unicode Clojure单元测试输出

当单元测试一些将ascii序列转换为unicode字符的代码时,我发现Clojure测试的输出存在问题.

我已经测试过我的终端可以输出unicode字符(通过捕获测试文件)并且工作正常,所以这个问题似乎与leiningen,Clojure或者clojure.test有关.

这是一个示例测试(使用unicode的希腊语部分 - 我也将使用希腊语扩展,但我认为同样的问题将适用):

(deftest bc-string-w-comma
  (is (= "???, ???" (parse "abg,*a*b*g"))))
Run Code Online (Sandbox Code Playgroud)

它意味着由于输入中缺少空间而失败.输出lein test如下:

Testing parse_perseus.test.betacode
FAIL in (bc-string-w-comma) (betacode.clj:15)
expected: (= "???, ???" (parse "abg,*a*b*g"))
  actual: (not (= "???, ???" "???,???"))
Testing parse_perseus.test.core
Testing parse_perseus.test.pluralise
Ran 10 tests containing 59 assertions.
1 failures, 0 errors.
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?这是终端仿真问题还是与clojure相关的问题?我在使用Slime/swank/emacs在REPL中运行代码时遇到同样的问题.emacs中的REPL仅输出unicode输出的问号(尽管emacs非常能够理解unicode).

我尝试在终端和iTerm(OS X)中运行此操作具有相同的结果.

unicode unit-testing clojure leiningen

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

在GridView中膨胀FrameLayout时出现ClassCastException

我正在尝试在GridView中膨胀FrameLayout并且我得到一个例外.这是来自适配器的getView方法(BaseAdapter的子类):

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO: Create compound view with image and name overlayed on top
    FrameLayout personFrame;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        personFrame = (FrameLayout)inflater.inflate(R.layout.thumbnail, null);
        //personFrame = (FrameLayout)View.inflate(mContext, R.layout.thumbnail, null);
        personFrame.setLayoutParams(new GridView.LayoutParams(85,85));
    } else {
        personFrame = (FrameLayout) convertView;
    }
Run Code Online (Sandbox Code Playgroud)

.... 等等

这是我正在膨胀的布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="85px"
android:layout_height="85px">
<ImageView
    android:id="@+id/thumbnail_image"
    android:layout_height="85px"
    android:padding="2px"
    android:layout_width="85px"
    android:scaleType="centerCrop" />
<TextView
    android:id="@+id/person_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="2dip"
    android:layout_gravity="center_horizontal|bottom"

    android:padding="2dip"

    android:background="#AA000000"
    android:textColor="#ffffffff"

    android:text="Me" /> …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
3
解决办法
9105
查看次数

标签 统计

android ×1

clojure ×1

leiningen ×1

rust ×1

unicode ×1

unit-testing ×1