小编Cam*_*art的帖子

在F#API中,有类似Option.ofNull的东西吗?

我从F#中使用的许多API都允许使用空值.我喜欢把它们变成选项.有一个简单的内置方法来做到这一点?这是我这样做的一种方式:

type Option<'A> with
    static member ofNull (t:'T when 'T : equality) =
        if t = null then None else Some t
Run Code Online (Sandbox Code Playgroud)

然后我就可以这样使用Option.ofNull:

type XElement with
    member x.El n = x.Element (XName.Get n) |> Option.ofNull
Run Code Online (Sandbox Code Playgroud)

是否有内置的东西已经这样做了?

根据丹尼尔的回答,equality不需要.null可以使用约束来代替.

type Option<'A> with
    static member ofNull (t:'T when 'T : null) =
        if t = null then None else Some t
Run Code Online (Sandbox Code Playgroud)

f#

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

仅为我的Web App配置Azure SQL数据库防火墙

我们将Azure Web AppsAzure SQL结合使用,并希望通过将数据库防火墙配置为仅允许从特定Web应用程序而非Azure中的任何服务进行连接来使此设置更安全.如何限制与Azure服务的连接?

firewall azure azure-web-sites azure-sql-database

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

如何从Rust FFI创建和返回C++结构?

我正在尝试创建并返回一个C++结构.我在cannot move out of dereference of raw pointer尝试编译时遇到错误.知道如何让这个工作吗?

#![allow(non_snake_case)]
#![allow(unused_variables)]

extern crate octh;

// https://thefullsnack.com/en/string-ffi-rust.html
use std::ffi::CString;

#[no_mangle]
pub unsafe extern "C" fn Ghelloworld(
    shl: *const octh::root::octave::dynamic_library,
    relative: bool,
) -> *mut octh::root::octave_dld_function {
    let name = CString::new("helloworld").unwrap();
    let pname = name.as_ptr() as *const octh::root::std::string;
    std::mem::forget(pname);

    let doc = CString::new("Hello World Help String").unwrap();
    let pdoc = doc.as_ptr() as *const octh::root::std::string;
    std::mem::forget(pdoc);

    return octh::root::octave_dld_function_create(Some(Fhelloworld), shl, pname, pdoc);
}

pub unsafe extern "C" fn Fhelloworld(
    args: *const octh::root::octave_value_list,
    nargout: ::std::os::raw::c_int, …
Run Code Online (Sandbox Code Playgroud)

ffi rust

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

具有泛型约束的F#成员重载

是否可以使用泛型约束来执行成员重载?在这里,我试图创建和AddWithOption方法来支持值类型和引用类型.如果你看一下要点,我会展示几次尝试来实现这一目标.

在此输入图像描述

我的解决方法只是不要重载成员.我将一个值重命名为AddWithOptionValue.但是,如果超载工作会很酷.有任何想法吗?

f#

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

标签 统计

f# ×2

azure ×1

azure-sql-database ×1

azure-web-sites ×1

ffi ×1

firewall ×1

rust ×1