www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I call this tamplte function?

reply Rib <neto.ribeiro email.com> writes:
to get get() from std.net.curl return a ubyte[] and use my http 
instance, all those failed:

string link = "http://...";
auto client = HTTP();
// set some client attributes...
auto fileContents = get!(AutoProtocol, ubyte)(link, client);
auto fileContents = get!(ubyte)(link, client);
auto fileContents = get!(client, ubyte)(link, client);

  I still didn't "get" D templates.
Jun 26 2018
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 06/26/2018 10:37 AM, Rib wrote:
 to get get() from std.net.curl return a ubyte[] and use my http 
 instance, all those failed:
 
 string link = "http://...";
 auto client = HTTP();
 // set some client attributes...
 auto fileContents = get!(AutoProtocol, ubyte)(link, client);
 auto fileContents = get!(ubyte)(link, client);
 auto fileContents = get!(client, ubyte)(link, client);
 
   I still didn't "get" D templates.
This worked for me: import std.net.curl; import std.stdio; import std.functional; void myHeaderReceivingFunction(const(char[]) key, const(char[]) value) { writefln("Received header: %s = %s", key, value); } size_t myDataReceivingFunction(ubyte[] data) { writefln("Received data; first part: %s", data[0..10]); return data.length; } void main() { auto client = HTTP("http://dlang.org"); // If you don't have an actual delegate, you can use std.functional.toDelegate: client.onReceiveHeader = (&myHeaderReceivingFunction).toDelegate; // ... or you can create a delegate with a lambda on the fly: client.onReceive = (ubyte[] data) { return myDataReceivingFunction(data); }; client.perform(); } Ali
Jun 26 2018