小编bat*_*teo的帖子

如何在 Svelte 3 中拥有条件属性?

是否有更简单的方法来编写以下复选框组件:

<script>
  export let disabled = false;
</script>

{#if disabled}
  <label class="checkbox" disabled>
    <input type="checkbox" {disabled} />
    <slot></slot>
  </label>
{:else}
  <label class="checkbox">
    <input type="checkbox" {disabled} />
    <slot></slot>
  </label>
{/if}
Run Code Online (Sandbox Code Playgroud)

拥有<label disabled="false">是不可接受的,因为布尔玛有一个 CSS 类.checkbox[disabled]

html svelte svelte-component svelte-3

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

sdl2-sys不会编译 - 无法执行链接器:没有这样的文件或目录

我正在关注这个Rust教程,并且正在努力编译第一个基础项目.我正在使用Fedora,但我是新手.

$ cargo build --verbose
   Compiling sdl2-sys v0.5.0
     Running `rustc /home/batisteo/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-sys-0.5.0/build.rs --crate-name build_script_build --crate-type bin -C prefer-dynamic -g --cfg feature="default" --out-dir /home/batisteo/arcade-rs/target/debug/build/sdl2-sys-d9571ac1c4bc4261 --emit=dep-info,link -L dependency=/home/batisteo/arcade-rs/target/debug/deps -L dependency=/home/batisteo/arcade-rs/target/debug/deps -Awarnings`
   Fresh libc v0.1.8
   Fresh bitflags v0.2.1
   Fresh rustc-serialize v0.3.15
   Fresh rand v0.3.8
   Fresh num v0.1.25
error: could not exec the linker `cc`: No such file or directory (os error 2)
error: aborting due to previous error
Could not compile `sdl2-sys`.

Caused by:
  Process didn't exit successfully: `rustc /home/batisteo/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-sys-0.5.0/build.rs --crate-name build_script_build …
Run Code Online (Sandbox Code Playgroud)

fedora rust sdl-2 rust-cargo

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

是否有一种 Pythonic 方法可以按最大字节数截断 Unicode 字符串?

如果 API 接受某些字节数限制的字符串值,但接受 Unicode,是否有更好的方法来缩短具有有效 Unicode 的字符串?

def truncate(string: str, length: int):
    """Shorten an Unicode string to a certain length of bytes."""
    if len(string.encode()) <= length:
        return string

    chars = list(string)
    while sum(len(char.encode()) for char in chars) > length:
        chars.pop(-1)

    return "".join(chars)
Run Code Online (Sandbox Code Playgroud)

python unicode python-3.x

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