+1, I have run into this awkwardness myself and wished the API were different, exactly as you outline.<br><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 27, 2016 at 03:16 Karl via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">Looking for feedback before submitting a PR: <a href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md" class="gmail_msg" target="_blank">https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md</a><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">—</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><h1 style="box-sizing:border-box;margin-right:0px;margin-bottom:16px;margin-left:0px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255);margin-top:0px!important" class="gmail_msg">Change (Dispatch)Data.<code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">withUnsafeBytes</code> to use <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:inherit;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">UnsafeMutableBufferPointer</code></h1><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">Proposal: <a href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/NNNN-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-NNNN</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Authors: <a href="https://github.com/karwa" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Karl Wagner</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Review Manager: TBD</li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Status: <span style="box-sizing:border-box;font-weight:600" class="gmail_msg">Awaiting review</span></li></ul><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><em style="box-sizing:border-box" class="gmail_msg">During the review process, add the following fields as needed:</em></p><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">Decision Notes: <a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Rationale</a>, <a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Additional Commentary</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Bugs: <a href="https://bugs.swift.org/browse/SR-NNNN" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SR-NNNN</a>, <a href="https://bugs.swift.org/browse/SR-MMMM" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SR-MMMM</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Previous Revision: <a href="https://github.com/apple/swift-evolution/blob/...commit-ID.../proposals/NNNN-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">1</a></li><li style="box-sizing:border-box;margin-top:0.25em" class="gmail_msg">Previous Proposal: <a href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/XXXX-filename.md" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">SE-XXXX</a></li></ul><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_1992592268771389802user-content-introduction" class="m_1992592268771389802anchor gmail_msg" href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md#introduction" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Introduction</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The standard library's <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Array</code> and <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">ContiguousArray</code> types expose the method <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">withUnsafeBytes</code>, which allows you to view their contents as a contiguous collection of bytes. The core libraries Foundation and Dispatch contain types which wrap some allocated data, but their <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">withUnsafeBytes</code> method only allows you to view the contents as a pointer to a contiguous memory location of a given type.</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Swift-evolution thread: <a href="https://lists.swift.org/pipermail/swift-evolution/" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none" class="gmail_msg" target="_blank">Discussion thread topic for that proposal</a></p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_1992592268771389802user-content-motivation" class="m_1992592268771389802anchor gmail_msg" href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md#motivation" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Motivation</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The current situation makes it awkward to write generic code. Personally, I use the following extension in my projects to sort the naming confusion out:</p><div class="m_1992592268771389802highlight m_1992592268771389802highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class="gmail_msg"><span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">protocol</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">ContiguousByteCollection</span> {
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">withUnsafeBytes</span><<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">T</span>>(<span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">body</span>: (UnsafeRawBufferPointer) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">throws</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> T) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">rethrows</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> T
}
<span class="m_1992592268771389802pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_1992592268771389802pl-c gmail_msg" style="box-sizing:border-box">//</span> stdlib types are fine.</span>
<span class="m_1992592268771389802pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span><span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">Array</span></span>: <span class="m_1992592268771389802pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">ContiguousByteCollection </span>{}
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">ArraySlice</span></span>: <span class="m_1992592268771389802pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">ContiguousByteCollection </span>{}
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)"><span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">ContiguousArray</span></span>: <span class="m_1992592268771389802pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">ContiguousByteCollection </span>{}
<span class="m_1992592268771389802pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"><span class="m_1992592268771389802pl-c gmail_msg" style="box-sizing:border-box">//</span> corelibs types give us a pointer<T>, should be: { pointer<char>, count }</span>
<span class="m_1992592268771389802pl-c gmail_msg" style="box-sizing:border-box;color:rgb(150,152,150)"></span>#<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> canImport(Dispatch)
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">import</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Dispatch</span>
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">DispatchData</span> : <span class="m_1992592268771389802pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">ContiguousByteCollection </span>{
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">withUnsafeBytes</span><<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">T</span>>(<span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">body</span>: (UnsafeRawBufferPointer) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">throws</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> T) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">rethrows</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> T {
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">try</span> withUnsafeBytes { <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">try</span> <span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">body</span>(<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafeRawBufferPointer</span>(<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">start</span>: <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">$0</span>, <span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">count</span>: count)) }
}
}
#<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span>
#<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> canImport(Foundation)
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">import</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Foundation</span>
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">extension</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">Data</span> : <span class="m_1992592268771389802pl-e gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">ContiguousByteCollection </span>{
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">withUnsafeBytes</span><<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">T</span>>(<span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">body</span>: (UnsafeRawBufferPointer) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">throws</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> T) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">rethrows</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> T {
<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">return</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">try</span> withUnsafeBytes { <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">try</span> <span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">body</span>(<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafeRawBufferPointer</span>(<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">start</span>: <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">$0</span>, <span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">count</span>: count)) }
}
}
#<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">endif</span></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Conceptually, the corelibs types <em style="box-sizing:border-box" class="gmail_msg">are</em> untyped regions of memory, and it would make sense for them to adopt the <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">UnsafeRawBufferPointer</code> model.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_1992592268771389802user-content-proposed-solution" class="m_1992592268771389802anchor gmail_msg" href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md#proposed-solution" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Proposed solution</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">The proposed solution would be to deprecate the current methods on (Dispatch)Data (with 2 generic parameters), and replace them with methods with identical signatures to Array (with 1 generic parameter).</p><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">To be deprecated:</p><div class="m_1992592268771389802highlight m_1992592268771389802highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class="gmail_msg"><span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">withUnsafeBytes</span><<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">ResultType</span>, <span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">ContentType</span>>(<span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">body</span>: (<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafePointer</span><ContentType>) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">throws</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> ResultType) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">rethrows</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> ResultType</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Replaced with:</p><div class="m_1992592268771389802highlight m_1992592268771389802highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class="gmail_msg"><span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">public</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">withUnsafeBytes</span><<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">R</span>>(<span class="m_1992592268771389802pl-en gmail_msg" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="m_1992592268771389802pl-smi gmail_msg" style="box-sizing:border-box">body</span>: (UnsafeRawBufferPointer) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">throws</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> R) <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">rethrows</span> <span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">-></span> R</pre></div><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_1992592268771389802user-content-source-compatibility" class="m_1992592268771389802anchor gmail_msg" href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md#source-compatibility" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Source compatibility</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Source-breaking. Users binding a (Dispatch)Data to an UnsafePointer would instead have to call:</p><div class="m_1992592268771389802highlight m_1992592268771389802highlight-source-swift gmail_msg" style="box-sizing:border-box;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)"><pre style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class="gmail_msg">buffer.<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">baseAddress</span><span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">!</span>.<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">assumingMemoryBound</span>(<span class="m_1992592268771389802pl-c1 gmail_msg" style="box-sizing:border-box;color:rgb(0,134,179)">to</span>: T.<span class="m_1992592268771389802pl-k gmail_msg" style="box-sizing:border-box;color:rgb(167,29,93)">self</span>)</pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Which is a bit more to type, although maybe the deprecation of the old function could provide this replacement as a fix-it.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_1992592268771389802user-content-effect-on-api-resilience" class="m_1992592268771389802anchor gmail_msg" href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md#effect-on-api-resilience" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Effect on API resilience</h2><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="gmail_msg">Source-breaking change to corelibs APIs.</p><h2 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25;padding-bottom:0.3em;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(238,238,238);color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class="gmail_msg"><a id="m_1992592268771389802user-content-alternatives-considered" class="m_1992592268771389802anchor gmail_msg" href="https://github.com/karwa/swift-evolution/blob/corelibs-unsafebytes/proposals/xxxx-corelibs-unsafebytes.md#alternatives-considered" style="box-sizing:border-box;background-color:transparent;color:rgb(64,120,192);text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u><u class="gmail_msg"></u></a>Alternatives considered</h2><ul style="box-sizing:border-box;padding-left:2em;margin-top:0px;color:rgb(51,51,51);font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255);margin-bottom:0px!important" class="gmail_msg"><li style="box-sizing:border-box" class="gmail_msg">A different method on <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Data</code> and <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">DispatchData</code>, providing an <code style="box-sizing:border-box;font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace;font-size:13.600000381469727px;padding:0.2em 0px;margin:0px;background-color:rgba(0,0,0,0.0392157);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">UnsafeRawBufferPointer</code>? There would still be a naming discrepency between the stdlib and corelibs types</li></ul><div class="gmail_msg"><br class="gmail_msg"></div></div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>