使用 GitHub Actions,在使用 Rust 的cargo.
我怀疑我忘记了以下代码中的某些内容,这里可能有什么问题?
编辑:如果您想查看的话,这是日志!
name: Rust
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cargo Cache
uses: actions/cache@v1
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
${{ runner.os }}-cargo
- name: Cargo Target Cache
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.toml') }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os …Run Code Online (Sandbox Code Playgroud) 我试图匹配下面的行不输入NOT包含"VelSign"(使用Notepad ++):
#MARKER VelSign 457.45 50 kmh
#MARKER IsBridge是真的
#MARKER TrafficSign 45
#MARKER TrafficLight 45 445 444 40
我使用以下正则表达式:
^#MARKER (?!.*VelSign).*$
似乎没有用.我究竟做错了什么?
我想在单独的线程上下载一个文件:
use http::StatusCode; // 0.2.1
use std::{fs::File, io::Write, path::Path, thread, time};
use reqwest; // 0.10.8
fn write_file(to_file: &str, response: reqwest::blocking::Response) -> std::io::Result<()> {
let content = response.bytes().unwrap();
let target_with_extension = Path::new(to_file);
File::create(&target_with_extension)
.expect("Unable to create file")
.write_all(&content)?;
Ok(())
}
pub struct Downloader;
impl Downloader {
fn get(&self, from_url: &str, to_file: &str) -> std::io::Result<()> {
let total_size: u64 = 1 * 1024 * 1024;
let download_thread = std::thread::spawn(|| {
let response = reqwest::blocking::get(from_url).unwrap();
assert!(response.status() == StatusCode::OK);
write_file(to_file, response).unwrap();
});
let fs …Run Code Online (Sandbox Code Playgroud) 在 Rust 中,使用sha256 = "1.0.2"(或类似),如何散列二进制文件(即tar.gz存档)?
我正在尝试获取该二进制文件的 sha256。
这不起作用:
fn hash() {
let file = "file.tar.gz";
let computed_hash = sha256::digest_file(std::path::Path::new(file)).unwrap();
computed_hash
}
Run Code Online (Sandbox Code Playgroud)
输出是:
...
Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }
Run Code Online (Sandbox Code Playgroud) 使用 C++14、17 或 20,我将两个模板参数传递给模板化类:TSize 和 MaxSize。
TSize 是 MaxSize 的类型。显然,两者在编译时都是已知的。TSize 需要足够大以适合 MaxSize。
template <typename TSize = uint8_t, TSize MaxSize = 15>
class Foo {};
Run Code Online (Sandbox Code Playgroud)
如何根据MaxSize的值自动推导出TSSize,所以我只要设置MaxSize的值就自动得到了?IE:
if MaxSize<256 -> TSize=uint8_t
if MaxSize<65536 && MaxSize>255 -> TSize=uint16_t
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
[以下回答问题的完整教程.欢迎反馈!]
我正在尝试创建一个AWS Lambda函数,用于Amazon Alexa技能从我的Netatmo weatherstation获取天气信息.基本上,我需要通过http请求连接到Netatmo云.
这是我的代码片段,http请求是为临时访问令牌完成的,请求没问题,但结果正文是正文:{"error":"invalid_request"}.这可能是什么问题?
var clientId = "";
var clientSecret = "";
var userId="a@google.ro";
var pass="";
function getNetatmoData(callback, cardTitle){
var sessionAttributes = {};
var formUserPass = { client_id: clientId,
client_secret: clientSecret,
username: userId,
password: pass,
scope: 'read_station',
grant_type: 'password' };
shouldEndSession = false;
cardTitle = "Welcome";
speechOutput ="";
repromptText ="";
var options = {
host: 'api.netatmo.net',
path: '/oauth2/token',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'client_id': clientId,
'client_secret': clientSecret,
'username': userId,
'password': pass,
'scope': 'read_station',
'grant_type': 'password'
}
}; …Run Code Online (Sandbox Code Playgroud) javascript amazon-web-services aws-lambda alexa-skill alexa-skills-kit
我正在尝试在 SWT 的文本字段中显示历史记录。
历史记录会生成一个新的 shell,其中有两个 Composites。第一个显示标题部分,其中包含标签“历史记录”和下方的水平线。第二个是页脚部分,显示实际数据。这是可行的,但水平线不会在整个可用水平空间中扩展(即:“填充”)(即:直到复合“结束”)。
public void mouseDown(final MouseEvent e) {
findSegmentText.setText("");
if(0 == lastSegmentIds.size()) return;
if(disableToolTipsButton.getSelection()) return; // context help is not desired
if(null != popupShell) popupShell.dispose();
popupShell = new Shell(Display.getDefault(), SWT.BORDER | SWT.ON_TOP | SWT.MODELESS);
//popupShell.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
popupShell.setLayout(createNoMarginLayout(1, false));
/* Header */
compositeSearchSegments1 = new Composite(popupShell, SWT.NONE);
compositeSearchSegments1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
compositeSearchSegments1.setLayout(createNoMarginLayout(1, false));
/* Footer */
compositeSearchSegments2 = new Composite(popupShell, SWT.NONE);
compositeSearchSegments2.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
compositeSearchSegments2.setLayout(createNoMarginLayout(2, false));
Label history = new Label(compositeSearchSegments1, SWT.NONE);
history.setText("History");
Label line1 = new …Run Code Online (Sandbox Code Playgroud) 在 C++14 中,我想限制枚举类所持有的总位数:
enum class InstalledCapacity : uint8_t{
None,
One_1000uF,
Two_1000uF,
Three_1000uF,
One_1F,
One_3_3F,
Reserved2,
Invalid
};
using HarvestingCapability = uint8_t;
typedef struct {
InstalledCapacity installed_capacity : 3;
HarvestingCapability harversting_capability_x_15mW : 5;
}EnergyInfo;
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用,我收到以下警告:
eeprom_metadata.h:51:42: warning: '<anonymous struct>::installed_capacity' is too small to hold all values of 'enum class InstalledCapacity'
InstalledCapacity installed_capacity : 3;
^
Run Code Online (Sandbox Code Playgroud)
由于我的枚举类中只有 7 个值InstalledCapacity,因此我希望只能使用 3 位。
我做错了什么,这可能吗?提前谢谢了!
是否可以使用 C++14 实现 C++17 结构化绑定?我的目标是使用以下语法进行简单的概念证明:
int a,b;
(a,b)=std::tuple<int,int>(4,2);
Run Code Online (Sandbox Code Playgroud)
我想象的方式是:
template <typename T, typename U>
operator=(operator()(T a, U b), std::tuple<T,U>(x,y))
Run Code Online (Sandbox Code Playgroud)
因此=,它向左接收一个“绑定元组”并将其分配给它。
这甚至可能吗?- 它是否可以用 C++14 实现,还是需要在后台进行词法分析/解析才能启用它?
编辑这是否可能不使用std::tie, 但使用 (a,b) 语法?
我正在使用TinyXML2开展一个项目.我正在尝试调用方法XMLAttribute*FindAttribute(const char*name)
该方法由实现定义为:
public :
const XMLAttribute* FindAttribute( const char* name ) const;
private :
XMLAttribute* FindAttribute( const char* name );
Run Code Online (Sandbox Code Playgroud)
关于方法如何在公共和私有范围内具有相同的签名,我有点困惑.我只能猜测它没有,虽然我并不真正理解公共定义末尾的const部分.但是,我需要调用public方法,但g ++ sais" tinyxml2 :: XMLElement :: FindAttribute(const char*)是私有的 "
如何调用公共方法,方法原型末尾的const部分是什么?
c++ ×4
rust ×3
c++14 ×2
alexa-skill ×1
aws-lambda ×1
c++20 ×1
java ×1
javascript ×1
label ×1
notepad++ ×1
regex ×1
sha256 ×1
swt ×1
tinyxml ×1