小编eve*_*992的帖子

如何将 JSDoc 注释添加到使用 typescript AST api 生成的 typescript?

如何使用 typescript 的 AST api 和打印机创建带有文档注释的函数?

/**
 * foo function
 */
function foo () {}
Run Code Online (Sandbox Code Playgroud)

以下代码生成该函数。

function foo () {}
Run Code Online (Sandbox Code Playgroud)
import ts from 'typescript';
const fooFunction = ts.createFunctionDeclaration(
  undefined,
  undefined,
  undefined,
  ts.createIdentifier("foo"),
  undefined,
  [],
  undefined,
  ts.createBlock(
    [],
    false
  )
)

const printer = ts.createPrinter({    
  newLine: ts.NewLineKind.LineFeed,    
});    

const resultFile = ts.createSourceFile(    
  "example.ts",    
  "",    
  ts.ScriptTarget.Latest,    
  /*setParentNodes*/ false,    
  ts.ScriptKind.TS      
);

const result = printer.printNode(
  ts.EmitHint.Unspecified,
  fooFunction,
  resultFile
);

console.log(result);
Run Code Online (Sandbox Code Playgroud)

code-generation typescript

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

你如何在课堂上声明一个泛型类的朋友?

下面的代码可以正常工作,但我想将ostream&operator <<移到类declearation之外,就像我使用hash :: operator []一样.

#include<iostream>
#include<map>

using namespace std;

template <class T>
class hash {
  private:
    map<string, T> _map;
  public:
    T& operator[] (string x);
    friend ostream& operator<<(ostream& out, const hash<T> &rhs) { return out << "test"; }
};

template <class T>
T & hash<T>::operator[](string x) {
  return _map[x];
}

int main () {
  hash<int> myobject;
  myobject["a"] = 1;
  cout << myobject["a"] << endl;
  cout << myobject << endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我试过了:

template <class T>
ostream& operator<<(...) {
  return …
Run Code Online (Sandbox Code Playgroud)

c++ generics templates friend

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

在继承的模型中跳过回调

是否有类似ActionController::Base#skip_before_filterActiveRecord回调的方法after_create?我有一些类的行为类似,为了减少代码重复,我创建了一个抽象类。抽象包含关系信息,验证和after_create创建新消息的回调。Message实现此抽象,因此保存消息会导致堆栈溢出。

我可以从模型中删除回调吗?

class Parent < ActiveRecord::Base
    self.abstract_class = true
    after_create :notify

    def notify
        Message.create
    end
end

class Message < Parent
    # skip after_create :notify
end

class Child < Parent
end
Run Code Online (Sandbox Code Playgroud)

abstract-class ruby-on-rails callback

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

elsaticsearch 中的源过滤、存储字段和文档值之间有什么区别?

我已经阅读了源过滤存储字段文档值的文档。

在某些情况下,存储字段是有意义的。例如,如果您有一个包含标题、日期和非常大的内容字段的文档,您可能只想检索标题和日期,而不必从大型 _source 字段中提取这些字段


stored_fields 参数是关于显式标记为存储在映射中的字段,默认情况下关闭,通常不建议这样做。使用源过滤来选择要返回的原始源文档的子集。


默认情况下,所有支持文档值的字段都启用它们。

实施例1

我有包含title(短字符串)和content(> 1MB)的文档。我想搜索匹配的标题,并返回标题。

  1. 带源过滤
GET /_search
{ _source: "obj.title", ... }
Run Code Online (Sandbox Code Playgroud)
  1. 具有存储字段
GET /_search
{ _source: false, stored_fields: ["title"], ... }
Run Code Online (Sandbox Code Playgroud)
  1. 带有文档值
GET /_search
{_source: false, stored_fields: "_none_", docvalue_fields: "title", ... }
Run Code Online (Sandbox Code Playgroud)

可以,然后呢

  • 源过滤请求是否会_source从磁盘读取完整的标题和内容,然后应用过滤器并仅返回标题,或者elasticsearch只会从磁盘读取标题?
  • 源过滤请求会使用文档值吗?
  • 存储字段存储分析后的标记还是原始值?
  • 存储的字段或文档值比 _source 效率更高还是更低?

elasticsearch

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

我可以在发散函数中使用问号运算符(?)来返回永不类型(!)吗?

我正在为嵌入式项目编写Rust,而我的main函数签名是

#[entry]
fn main() -> !
Run Code Online (Sandbox Code Playgroud)

我知道这意味着它永远不会返回,而且我通常在main的末尾进入无限循环。

我想?在主要功能中使用try运算符,但无法在文档中搜索rust ? in !。我该如何用单词拼写出来?

我可以?() -> !功能中使用吗?

rust

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